1
一切正常工作在其他機器人,但在6.0 MyLocationButton不會做任何事情。這是我的代碼Android:我的位置按鈕不適用於Android 6.0
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.setMyLocationEnabled(true);
googleMap
.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
Location location = googleMap.getMyLocation();
if (location == null) {
checkLocationSettings();
return true;
}
LatLng locationLatLng = new LatLng(location
.getLatitude(), location.getLongitude());
setMarkerToMap(locationLatLng);
//other staff
return false;
});
protected void checkLocationSettings() {
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
.checkLocationSettings(mGoogleApiClient,
mLocationSettingsRequest);
result.setResultCallback(this);
}
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
}
break;
}
}
什麼會導致此問題?我想它必須做一些新的權限(在Android 6.0中),但我無法弄清楚。
您是否嘗試過檢查裏面OnClickListener ACCESS_FINE_LOCATION許可verifyStoragePermissions()方法,並呼籲在onCreateView()活動的 ? – noktigula