我正在尝试使用“ FusedLocationProviderClient”获取当前位置以在地图上显示它 但它在android棒棒糖中不起作用,尽管在上述所有版本中都可以正常工作。下面是代码示例,我正在尝试做。
if (checkSelfPermission(getActivity(),Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(getActivity(),Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return v;
}
fusedLocationProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
mLastLocation=location;
getAltitude();
if(mMap!=null){
if(location!=null){
Marker marker=mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(),location.getLongitude())));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()),15.0f));
}
}
}
});