【发布时间】:2019-04-01 10:27:20
【问题描述】:
我使用 fusedlocation 提供程序客户端获取设备位置。但如果位置设置关闭我的手机并使用 locationServices 打开位置设置。 getSettingsClient 融合位置提供者返回 null
final Task<Location> locationTask = fusedLocationProviderClient.getLastLocation();
locationTask.addOnSuccessListener((Activity) context, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
lastKnownLocation = location;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(lastKnownLocation.getLatitude(),
lastKnownLocation.getLongitude()), Constants.DEFAULT_ZOOM));
LatLng position = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
HashMap<String, String> adressInfo = MapUtility.getAddressGeocoderObject(context, position);
MapUtility.moveCamera(context, map, position, Constants.DEFAULT_ZOOM,
adressInfo.get("addressFeatureName"), adressInfo.get("remainAdress"));
} else {
Toast.makeText(context, "null", Toast.LENGTH_LONG).show();
//map.getUiSettings().setMyLocationButtonEnabled(false);
}
【问题讨论】:
标签: android google-maps null android-fusedlocation