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

前端 未结 6 2022
抹茶落季
抹茶落季 2020-12-07 15:03

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:

6条回答
  •  心在旅途
    2020-12-07 15:16

    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

提交回复
热议问题