Main navigation

Google Map Tutorial in Android Studio: How to get current location in Android Google Map


What’s Next

Now that you have made an App to display your current location, you can learn How to Draw Route between two points using Google Directions in Google Map Android API V2. Moreover you can learn How to search nearby locations and add marker on places like Restaurants, Schools, Hospitals etc. in Google Maps.

We hope you like our Google Maps Tutorial. Please comment if you have any doubts or suggestions. Don’t forget to subscribe. Also do Like our Facebook Page or Add us on Twitter. Happy Coding :).

You can download full code here:

Android Tutorial Point Download Now

Reader Interactions


  1. I am trying to build the app and ran into a problem on line 90 in mapsactivity. cannot resolve ‘mGoogleApiClient’ in the onConnected() method. thanks

    • Hi Paul,

      Open the build.gradle file for the app module and see dependencies section at the bottom:

      dependencies {

      compile fileTree(dir: ‘libs’, include: [‘*.jar’])

      compile ‘’

      compile ‘’


      The last line above is the important one to pull in Google Play
      Services. Please match this and let us know if it resolves your issue.

  2. O M G this is the best tutorial ive found and really really good explanations!

    Thanks so much!

    I would have one suggestion. Could you write additionally a code to this “current location app”, which shows all locals, bars, restaurants & discos in a self selected radius?

    Im looking for a code since 2 days and i rly cant find helpful links.

  3. its working good thanks but i face a error in my logcat


    Process: com.example.taimoorcheema.login, PID: 19375

    java.lang.ClassCastException: com.example.taimoorcheema.login.activityDrawer.HomeFragment cannot be cast to

    at com.example.taimoorcheema.login.activityDrawer.HomeFragment.onConnected(

    at Source)

    at Source)

    at Source)

    at Source)

    • Make sure your Activity implements and not android.location.LocationListener.
      You may have imported android.location.LocationListener by mistake.

      • am having same problem….
        this doesnt solve my problem
        LocationListener is shown red

    • Hi Adu Wolde,

      There could be three reasons for it, please confirm each of them:

      1) I hope you are running it on a real android device (like smartphone etc.) because it won’t work on an emulator.
      2) You have turned on your GPS and device is connected to Internet.
      3) You have generated your own key (Server Key) according to the link given in your project and not using our key as specified in tutorial.

      Let us know if it works fine. All the Best !!


          • Hi Chethan,

            Please make sure that above three points which we have written in the answer are obeyed by you. If you still can’t see markers then we will suggest you some other things.

            • Hi,

              Actually i am obeying all the 3 points as mentioned above. Even after that i am not able to see any marker.

              What should be the reason for that?

              Thanks in advance!

          • Actually it does work in the emulator. You just need to send a GPS coordinates to it, or replay a pre-recorded GPX file.

            On the other hand, when I got the issue where it shows the map but didn’t get the crossbar, there are two things I need to do: 1) trigger checkLocationPermission() in onCreate(), so that I get prompt to allow permission and 2) I put in the actual API key in AndroidManifest.xml, but that didn’t work. I have to use ‘@string/google_maps_key’ as in the tutorial instead.

  4. Hello, I am unable to run the app on my device sdk(API 18).
    my dependencies section looks like this.

    dependencies {
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
    testCompile ‘junit:junit:4.12’
    compile ‘’
    compile ‘’

    • Hi James,

      As I have referred in below comment please check following three conditions:

      1) I hope you are running it on a real android device (like smartphone etc.) because it won’t work on an emulator.
      2) You have turned on your GPS and device is connected to Internet.
      3) You have generated your own key (Server Key) according to the link given in your project and not using our key as specified in tutorial.

      Let us know if it works fine. All the Best !!


  5. It works for me but whenever I change my location the onLocationChanged method is not called and tha marker is not updated. please help

    • It is happening because this is what expected in code. Have a look at following code snippet:
      //stop location updates
      if (mGoogleApiClient != null) {
      LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

      I hope this explanation answer your query. All the best 🙂

  6. hello, thanks a lot for the code! i’ve a question…if i want to use the currrent location parameters (lat and longitude) in order to do additional things how do i get them updated? do i need to set them as global variables? thanks in advance

  7. Thanks for a good tutorial, i have made app useing your code, but Marker not updated while location change
    and app did not prompt for make turn on gps and internet when it Off

    • Because it stops location updates in onLocationChanged method.

      //stop location updates
      if (mGoogleApiClient != null) {
      LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

      • Thanks Kamil for answering query of user. You are right. Locations are not updating due to removeLocationUpdates(). Let us know if you want any other tutorial to be included on Android Tutorial Point. We will surely add it.

        Android Tutorial Point

        • thank you so much for creating this tutorial dude, it’s help me a lot. would you make tutorial how to change the default mylocation icon on the map to My Location Floating Button like google maps new version ? 🙂

          or How to call myLocation from float button

          • That’s a nice suggestion. Right now there are some tutorials in line like Chat App and Login-Registration, after that we will surely make this one. All the best 🙂

  8. So why does this crash in the emulator (SDK < 23)? If I go into the settings, the location permissions are granted, but I get this error when I click on the map to get directions:

    java.lang.SecurityException: Permission Denial: starting Intent { (has extras) } from ProcessRecord{360e8a31} (pid=4014, uid=10036) not exported from uid 10007

    Would like to be able to make sure it works on the emulator in various versions before I go shipping it off to the app store.. I don't have a physical device that's < SDK 23..

    • Hi Billdacat,

      I have not tried this app on an emulator, but I don’t think so it will work on it. Google Maps current location tutorial won’t work on an emulator irrespective of SDK. I think major reason behind this is unavailability of Real GPS. So I would suggest you to run this app on any android smartphone. It will surely work.
      Moreover all latest developments in android are backward compatible and hence this tutorial should be valid for older versions too, though I have not tried it. All the best (y) 🙂

      • Hi and thanks for your good tutorial.
        I do not have device to test it and my only option is emulator. I think there should be a way that it works and show current location in emulator. May u pls help in this case and give a solution to use emulator with no problem?

  9. i have many errors …..pls help
    *can’t resolve symbol ‘locationrequest’
    *can’t resolve symbol ‘locationservice’
    *can’t resolve method ‘setpriority(),setintervals(int),setfastestinterval(int)’……

    • Hi Chethan,

      Have you added compile ‘’ in your build.gradle file and then did sync? That could be one of the reason of these errors. If issue still persist then we need to see your code. All the best !!

    • include this in defaultconfg
      – multiDexEnabled true
      and this on in dependencies
      -compile ‘’

      In your manifest add the MultiDexApplication class from the multidex support library to the application element.

  10. Hi! I made an end location too, coz i wanted to see how far my location is to the place i want to go. how can I focus (or zoom out) my camera on both my start location and end location?

    • If you want to focus camera on both start and end location then choose a location exact in between origin and destination. You can try to take average of longitude and latitude and then focus camera. Also zoom out according to distance between points. All the best 🙂

  11. Hi and thanks for your good tutorial.
    I do not have device to test it
    and my only option is emulator. I think there should be a way that it
    works and show current location in emulator. May u pls help in this case
    and give a solution to use emulator with no problem?

    • Hi devandroider,

      You need to set the latitude and longitude in case of emulator because emulator do not have gps detection hardware to get current location. Hence in short it won’t work on an emulator. You have to use real android device.

  12. I do not understand what you mean by Click ALT ENTER. When I type those three callbacks, there is only a red underline under the comma. I am new to Android and am using Android Studio. Is there something I can type manually instead?

    Kindly let me know!


    • Yes, you can manually add those lines which we are suggesting you through ALT+ENTER. You can even Download full code through DOWNLOAD NOW button and then compare your code with the one we provided. All the Best !!

  13. but my location button is showing no results on clicking it ,means it’s not updating my location when using it on marshmallow version android phone.pls help

    • Hi Sakshi,

      It should work on all versions. Please download code from download now button and run it. It will work for sure.

  14. You are doing great work here.
    I loved this tutorial and that push me to read another tutorials on your site.
    Thank you

  15. You are a God…I’m just saying as I’ve been trying to figure this out for weeks now…and you’re code is the only one that works!

    • If you want to Zoon then you can do required changes in camera: mMap.animateCamera(CameraUpdateFactory.zoomTo(11));

  16. Awesome Tutorial. After struggling for a long time, I just came across your page and this was the perfect guide. Thanks a lot guys. Would really love to see more of such tutorials.

  17. It doesn’t center when I open it up immediately, I need to press the location key to get it to move the camera where I currently am, is there a way I can do this automatically on open? As in open->get current->move camera immediately.

  18. When I was searching android map information on google, I couldn’t get good tutorial on it. After searching some more, I found this blog and you are doing awesome job here.

    Keep it up.

  19. i have error on …..pls help
    No suitable method found or removeLocationupdate, cannot convert to Locationlistener

  20. i need help please, i can run the whole code but the when tested in phone theres no map,only ui with location symbol..not even a marker popup

  21. I typed the code as I went and learned the why’s of the code. I ran it on my phone and it stumbled. But then looked it over and tweaked it oh so lightly. AWESOME instruction. Very well done all.
    I am looking to design an map app that allows for the location of close friends with markers; do you have a
    starting point for my research ?
    {Self taught 60 year old programmer; C++, Java}

  22. Hy, thanks for this tutorial. It’s very helpful !! 🙂

    When I’m running my code, I didn’t have any errors, but in the application, appears just the map without my location marker. You have any idea, why is happening this?
    I think so I’m doing everything right!

    Thanks 🙂

  23. Everything is very open with a very clear explanation of the
    challenges. It was truly informative. Your website is extremely helpful.
    Many thanks for sharing! math problem,
    Cool blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my blog stand out.
    Please let me know where you got your design. Thanks

  24. Hi thanks for this good tutorial

    everything is done right, google map accessible , but correct current location not showing in genymotion emulator, when i try to build apk, but it can’t build and giving error ” Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’.
    > java.util.concurrent.ExecutionException: method ID not in [0, 0xffff]: 65536″

  25. I absolutely love your blog and find many of your post’s to be just what I’m looking for.
    can you offer guest writers to write content to suit your needs?
    I wouldn’t mind composing a post or elaborating on some of the subjects you write with regards to here.
    Again, awesome web log!

  26. ooh it’s really soo soooo helpful thank u so much sir I just like to suggest to make a tuto like this to explain how to develop an app of nearest pharmacy, I need it, please

  27. Hi, thanks for the nice tutorial. I followed it and I run my app but it crashes. It seems to be one probem into the code:
    if (mGoogleApiClient != null) {
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
    I encountered an error with above code and cast the 2nd parameter this way:
    ( this;
    but it didn’t work.

    Do you have any suggestion to solve this issue?
    Thank you in advance

    • Hi guys, I solved the issue. Just to inform you, if you have the same problem: you should check on your imported library, it has to be “” not “android.location.LocationListener”.

  28. Hi, thanks for the nice tutorial. I followed it step by step and encountered an issue into the code:
    in “onLocationChanged”
    if (mGoogleApiClient != null) {
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
    there’s an error into the code and I had to cast the 2nd parameter, but it didn’t work. The app crashes.
    The same thing in “onConnected” method, 3rd parameter of “requestLocationUpdates”.

    Do you have any suggestions?
    Thank you in adavance

  29. Thank you for the auspicious writeup. It in fact was a amusement account
    it. Look advanced to more added agreeable from you!
    By the way, how could we communicate?

  30. Asking questions are trruly pleasant thing if you are not understanding something fully, except this post gives pleasant understanding yet.

  31. Hi The above code works fine in below Android 6 . But Latitude and Longitude are showing (0,0) in Android 6.0 and above

  32. Hi there! This post couldn’t be written uch better!Going through this article reminds me of my previous roommate!
    He always kept talking about this. I am going to forward this post to him.
    Fairly certain he’s going tto have a very good read.
    Thank you for sharing!

  33. How to share your movement on a map with a third party for monitoring purpose ? Any help in this regard would be much appreciated.
    Thanking in advance.

  34. I am not certain where you are getting your information, however great topic.
    I must spend a while learning much more or understanding more.

    Thank you for fantastic info I used to be in search of this info for my mission.

  35. Hey.. I like your tutorials very much..these are very good.
    but this time i am facing a problem,previously i got exact current location but this time i didnot…i donot know whats wrong with it.. will you plz help me.
    why i am not getting current location now…this time it just show the map,no even any single location

  36. It’s going to be end of mine day, however before finish I am reading
    this impressive article to increase my knowledge.

  37. Hey! Would you mind if I share your blog with my twitter group? There’s a lot of people that I think would really appreciate your content. Please let me know. Thanks

  38. public boolean checkLocationPermission()

    this method was created but never used? Or how its used in code? I didn’ t get that?

    • @Override
      protected void onCreate(Bundle savedInstanceState) {

      if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()

  39. hey im getting an error regarding the depedencies

    dependencies {
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
    testCompile ‘junit:junit:4.12’
    compile ‘’
    compile ‘’

  40. Struggling with this…..first part worked ok, showing marker in Sydney but when i followed the next part it all goes wrong. Ive even copied your code into Android Studio and get all the same errors. Read through all these comments and edited what i could but still doesnt work. Frustrated as i need something like this for an app im working on and no other examples or codes out there work at all.

    ERROR: Unused import statement & Cannot resolve symbol LocationListener
    Unused import statement & Cannot resolve symbol LocationRequest
    Unused import statement & Cannot resolve symbol LocationServices

    LocationListener, LocationRequest and LocationServices all RED throughout code.
    Tried modifying and changing but failed.

    Need to resolve this issue to continue, hate getting to end of a project and errors appear.

    Can you email me response?

    • Hi Rick,
      You are probably missing one of the dependencies in the build tool. Check your build.gradle file:

      dependencies {
      compile fileTree(dir: ‘libs’, include: [‘*.jar’])
      androidTestCompile(‘’, {
      exclude group: ‘’, module: ‘support-annotations’
      compile ‘’
      compile ‘’
      compile ‘’
      testCompile ‘junit:junit:4.12’

  41. “Best Blogpost! Hi there! This is my first comment here so I just wanted to give a quick shout out_ and tell you I genuinely enjoy reading through your posts. Can you recommend any other blogs/websites/forums that deal with the same topics?”

  42. if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this,
    Manifest.permission.ACCESS_FINE_LOCATION)) {
    In my code error is showing in checkSelfPermission, shouldShowRequestPermissionRationale ,requestPermissions it is marked red showing cannot resolve method.
    Please help and eply soon…

  43. shouldShowRequestPermissionRationale ,requestPermissions,checkSelfPermission
    In all these it showing red and error occured cannot resolve the symbol. i M NOT ABLE TO resolve the error so please help me about this soon.
    Please reply……

  44. In my code error is showing in checkSelfPermissions, requestPermissions.
    Cant resolve thses symbol please help me…

  45. not able to acess prmission from manifest file ACCESS_FINE_LOCATION
    if (ContextCompat.checkSelfPermission(this,

    != PackageManager.PERMISSION_GRANTED) {

  46. No error is showing. Maps rendering , but current location not showing. In all your tutorials, only maps getting displayed, no current location, no route, no distance , no time….I dont know where m i going wrong.

    • This was also happened with me then i changed my google API key and added a new server API key and it is working fine…Try may it works.

    • Same problem was their in my code as well so u need change ur Google server api again and it will work……….

    • Write these following lines in onCreate Method

      if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

  47. This is a pretty good tutorial…however…the big but…

    If you’ve come here thinking that you will find an answer on how to write a more complex app using location services then you will probably run around in circles, especially if you are new to Android and are easily seduced by its simplicity. Because it isn’t as simple as this.

    The author doesn’t mention a number of subtleties which may cause you to wonder what is going on:

    1) If you run this code in a debugger you’ll notice that you only get one invocation to location changed

    That’s because ongoing location changes is switched off. He doesn’t say why, he just does it below “//stop location updates”.

    2) If you uncomment the code that switches off location changes, and observe behaviour in a debugger

    You’ll notice that this gets called a lot, especially if you are in-doors. It might be an interesting question to explore how to handle jitter in the GPS locations reported.

    3) But you might not have been aware of 1) and 2) but you are still observing location updates in a debugger?

    How is that even possible? Well, that’s because the author left out one major item from the discussion…which is that the Activity object you are debugging might be changing all the time. It might not even be the same object.

    This had me puzzled for some time. I was looking at the id of the Activity object and I noted that it was changing. I noticed this because “mCurrLocationMarker != null” was never triggered. mCurrLocationMarker as the code is written here will never be anything else but null on entry to this method, as long as you don’t make change 2).

    How is that possible? You can see that it is set in the code? Well it is set, but the object it is set in won’t be the object you see it in the next time your android studio debugger comes in to look at it.

    That’s because you probably performed a configuration change. “A what?”. Well, in your playfulness you might have moved your phone while connected to some other location in the room just to see location changing. And then a configuration change was triggered. And when that happens the Activity object is destroyed and recreated. Hence the code “protected void onCreate(Bundle savedInstanceState)”. savedInstanceState. That is a clue, but the author doesn’t discuss it. Indeed there is no save instance state method, so there is nothing saved. You end up with a clean Activity object everytime you tilt your phone.

    This took me a couple of hours to figure out, so I thought I’d write this up here to give someone else a chance of not getting very frustrated.

    4) If you need to write a more complex application you will have to look at background services, parcelable and so on….

    Then it starts to become complicated. But if you didn’t waste 2-3h scratching your head, you might have energy left in you to invest in that.

    Good luck!

  48. For all of those who only see a map and not your location, you must put these lines in the onCreate(…) method:

    if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

    I had the same problem, I guess it’s not explained in the tutorial.

  49. i am new on android studio.After i copy the code it show several error. At Map.Activity java , R at R layout activity map and R id map is undefined. Another error is from android manifest file , android:name=”.MapsActivity”. Map Activity unable to resolve. Anybody know how to solve the error

  50. Hey, everything is fine but when I try to run the app this message pops out: “Unfortunately, Google Maps App has stopped”; and I tried twice but no succes. Any advice?:) Many thanks:)

  51. i literally didn’t get any marker anywhere in the whole map , where did i go wrong please? i even copied the whole code but nothing changed

  52. When I run basic google app it shows a blank screen with google appearing on the lower left corner.
    kindly advise please.

  53. Not only it works just fine, but I checked the comments and you really took your time to reply to others’ issues!!!
    Hats off to you, Sir! Great way to study android programming!

  54. An Important Modification in Build.gradle for LocationRequest class and Location Service.
    Please Add following one line in build.gradle.

    compile ‘’

    • Hey, did you use your phone or some emulator for output?:) I used my phone and when I run the app an error occurs and the app stops

  55. Hello, Great tutorial. But i get an @Overide error on this.. Newby here dont be to hard on me lol.. It says this on these three overrides
    error: method does not override or implement a method from a supertype

    public void onStatusChanged(String provider, int status, Bundle extras) {


    public void onProviderEnabled(String provider) {


    public void onProviderDisabled(String provider) {

  56. LocationService error.


    Tried everything mentioned above but nothing make it work.

  57. Thank you so much for creating this tutorial. really it helps me a lot. Would you help me how to periodically send my current location to my friend remotely on google map.

  58. Hi Team,

    I copy pasted the code in Android Studio version 2 .
    I got following error on Line 149:
    getMenuInflater().inflate(, menu);
    Error:(149, 36) error: cannot find symbol variable menu
    Line 160 : if (item.getItemId() == {
    Error:(160, 37) error: cannot find symbol variable option_get_place

    Please help.

  59. Hi, I got a problem the all code looks good, but My android Studio don’t recognized the ”Manifest.permission.ACCESS_FINE_LOCATION” How can I Fix it?

    I’m using
    CompliledSDK: 25

    compile ‘’
    compile ‘’
    compile ‘’
    compile ‘’
    compile ‘’
    testCompile ‘junit:junit:4.12’

  60. hi, greart tutorial.
    I got a problem the all code looks good, but My android Studio don’t recognized the
    i m using CompliledSDK: 25

  61. dependencies {
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
    androidTestCompile(‘’, {
    exclude group: ‘’, module: ‘support-annotations’
    compile ‘’
    compile ‘’
    testCompile ‘junit:junit:4.12’

    My code looks like this. Instead of play-services it shows play-services-maps.
    How can I change it?

  62. this tutorial was really helpful for my project.thanks for you have app for present location can tracked with location name and it can be save in sms message body part or that app can be given the present location with attachment of the message for reciever

  63. dependencies {
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
    androidTestCompile(‘’, {
    exclude group: ‘’, module: ‘support-annotations’
    compile ‘’
    compile ‘’
    testCompile ‘junit:junit:4.12’

    My code looks like this. Instead of play-services it shows play-services-maps.
    How can I change it?

  64. If i want to take the current location’s latitude n longitude and display it on another activity .. it is possible ?
    If yes, how ?

  65. Hello,
    Thanks for this tutorial. But now I want to draw a rectangle (Just like circle) through radius. Can u please help me out?


  66. Sir Can you add codes here to show the local address of the current place as the title of the marker please …
    Using Geocoder or something else..
    please sir.

  67. i have used
    compile ‘’
    compile ‘’
    compile ‘’
    its not working for me app gets force closed

  68. Is there a ways I can save Google Maps offline or make maps offline? I tried to find resources in the internet but they are old already and use other API. I’m a beginner with Android Studio. Thank you so much.

  69. Just curious, in onLocationChanged(), you have these:


    Does it suppose to re-center the map to your current location? Because mine isn’t doing it.

  70. hi
    i am developig an android app , I need help in point a specific location of my office,which I am failing to do, can u please suggest me any appropriate method or any map api which can always pin point a specific location


Leave a Reply

Advertisment ad adsense adlogger