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

 

Published by

Saidur

Saidur Rahman, Passionate Software Engineer. I try to spend most of my time with Problem Solving and Android Development. I love Web Development and Designing too.

2 thoughts on “How to get current location in Android Google Map (FusedLocationProviderApi)”

  1. Helpful Article for me. I’m very new at android. I need your advice. I want to insert longitude and latitude into MySQL. Most of my user are accessing my website from android phone. My Geo location works for PC but not for mobile browser. Some of my user’s android version are 4.3. Some are 4.4. And off course some are 6.0 too. So what should I do to get log and lat from mobile user?

    Thanks in advanced.

     
    1. Hello Kaniz,

      If my understanding is correct, you want to take lat and long value of your current location. Yes, you can do it. In onLocationChanged() function you can declare two new variable and get the location.getLatitude() and location.getLongitude() value. Then you can insert these data to your mysql.

      Thanks.

       

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">