Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 447
Yos233 Avatar asked Feb 28 '13 17:02

Yos233


People also ask

How do I turn on my location on Google Maps Android?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


1 Answers

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

like image 50
Yos233 Avatar answered Sep 26 '22 10:09

Yos233