Wednesday 1 October 2014

HB Blog 21: Google Map Geo-Fencing Android [Tutorial].

    There are many places on Internet where you can find how to integrate Google Map using Android Api. You can try out few below links that can guide you to start it.

http://developer.android.com/google/play-services/maps.html
http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/
http://www.tutorialspoint.com/android/android_google_maps.htm
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html

But,in this tutorial I would like to move on with it. This tutorial will explain how to integrate geo-fencing in Google map.

Firstly, Integrate Google map - that you can using above few links.
In short, you need

Google Map - Activity file to create an object of GoogleMap and get the reference of map from the xml layout file.
Google Map - Layout file to add the map fragment.
Google Map - AndroidManifest file to add some permissions along with the Google Map API key.

Secondly, add marker and addCircle as below code snippets,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Marker stopMarker = googleMap.addMarker(new MarkerOptions()
.draggable(true)
.position(new LatLng(latitude, longitude))
.title(title)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));

googleMap.addCircle(new CircleOptions()
.center(new LatLng(latitude, longitude)).radius(radius)
.fillColor(Color.parseColor("#B2A9F6"))); 
Finally, add your api key in android manifest.I hope you added during map integration. Now, you can run your app and hope you try out other google map attributes as well.

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File

No comments:

Post a Comment