How to display my location on Google Maps for Android API v2

Yos233 picture Yos233 · Feb 28, 2013 · Viewed 140.2k times · Source

I've looked high and low for an answer on this, and no one, in any forum question has been able to help. I've searched through the tutorials. The API Guide says:

The My Location button appears in the top right corner of the screen only when the My Location layer is enabled.

So I've been looking for this My Location layer and have been unable to find anything. How do I show my location on a Google Map?

Answer

Yos233 picture Yos233 · Feb 28, 2013

The API Guide has it all wrong (really Google?). With Maps API v2 you do not need to enable a layer to show yourself, there is a simple call to the GoogleMaps instance you created with your map.

Google Documentation

The actual documentation that Google provides gives you your answer. You just need to

If you are using Kotlin

// map is a GoogleMap object
map.isMyLocationEnabled = true


If you are using Java

// map is a GoogleMap object
map.setMyLocationEnabled(true);

and watch the magic happen.

Just make sure that you have location permission and requested it at runtime on API Level 23 (M) or above