How can I show current location on a Google Map on Android Marshmallow?

后端 未结 3 1309
夕颜
夕颜 2020-11-21 22:56

I want google maps to show the location of the user. I tried this code, but it did not work on Android 6.

private GoogleMap map;
LocationManager lm;
Location         


        
3条回答
  •  野性不改
    2020-11-21 23:09

    Sorry but that's just much too much overhead (above), short and quick, if you have the MapFragment, you also have to map, just do the following:

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                googleMap.setMyLocationEnabled(true)
    } else {
        // Show rationale and request permission.
    }
    

    Code is in Kotlin, hope you don't mind.

    have fun

    Btw I think this one is a duplicate of: Show Current Location inside Google Map Fragment

提交回复
热议问题