Google地图无法在设备上加一(Marshmallow)

时间:2016-07-31 01:22:37

标签: android google-maps

为什么地图和位置不能在设备上加一(Marshmallow),而在其他设备中(我尝试在Kitkat和棒棒糖中工作)?这样就无法检测到我们的位置

enter image description here

这是我的代码

private void setMap() {
        mMapFragment.getMapAsync(this);

    }
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                Place place = PlacePicker.getPlace(getApplicationContext(), data);
                LatLng latLng = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude);
                googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
            }
        }
    }
@Override
    public void onMapReady(GoogleMap googleMap) {
        this.googleMap = googleMap;

        this.googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

        GoogleMapOptions option = new GoogleMapOptions();
        option.compassEnabled(true);
        this.googleMap.setTrafficEnabled(true);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        googleMap.setMyLocationEnabled(true);

        googleMap.setOnMyLocationChangeListener(myLocationChangeListener);

    }

    private OnMyLocationChangeListener myLocationChangeListener = new OnMyLocationChangeListener() {
        @Override
        public void onMyLocationChange(Location location) {
            if(awal) {
                awal=false;
                googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(13));
            }
        }
    };

1 个答案:

答案 0 :(得分:1)

我认为你需要地图的运行时权限,Marshmallow需要资源的运行时权限。请参阅以下链接

Permission issues for location in android Marshmallow applicaton