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

前端 未结 6 2024
抹茶落季
抹茶落季 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:18

    From android 6.0 you need to check for user permission, if you want to use GoogleMap.setMyLocationEnabled(true) you will get Call requires permission which may be rejected by user error

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

    if you want to read more, check google map docs

提交回复
热议问题