Android:我的位置按钮在Android 6.0上无效

时间:2016-05-12 10:47:41

标签: android google-maps google-play-services android-6.0-marshmallow

在其他机器人中一切正常,但在6.0中,MyLocationButton不做任何事情。这是我的代码

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中),但我无法弄明白。

1 个答案:

答案 0 :(得分:0)

请参阅这些链接并在运行时添加权限。

https://blog.xamarin.com/requesting-runtime-permissions-in-android- 棉花糖/

或尝试这些

创建verifyStoragePermissions()方法并在onCreateView()中调用 活动

<tr data-ng-repeat="target in targets | filter:search | startFrom:(currentPage - 1) * pageSize  | limitTo: pageSize "> 
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].YEAR"></td>
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].MONTH"></td>
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].TV"></td>
</tr>