How to get current location in Android Google Map (FusedLocationProviderApi)

In this tutorial , we will learn how to make a Google Maps App that shows your current location. Best to use the FusedLocationProviderApi now, as it offers less battery drain than the old open source LocationManager API. Also, if you’re already using Google Play Services for Google Maps, there’s no reason not to use it. I have added sample code in Github, you can download the code from here (Download Code).

YouTube Video:

 

NOTEYou have to provide your own API_KEY in google_maps_api.xml, otherwise location will not display in your application.

Creating new Android Project:

1) Open Android Studio and make a new project with name “Current Location”  and company domain app.test.currentlocation.saidur.me.currentlocation;

2) Click Next and choose android version Lollipop. Again Click Next and Choose Google Maps Activity.

3) Leave all things remaining same and Click Finish.

Now you will be able to see three files:

  • google_maps_api.xml (…/GoogleMapsApp/app/src/debug/res/values/google_maps_api.xml)
  • MapsActivity.java (…/GoogleMapsApp/app/src/main/java/com/androidtutorialpoint/googlemapsapp/MapsActivity.java)
  • AndroidManifest.xml ( …/GoogleMapsApp/app/src/main/AndroidManifest.xml)
Read More