Android 禁用谷歌地图中的自动缩放

Android 禁用谷歌地图中的自动缩放,android,google-maps,Android,Google Maps,我制作了一个android应用程序,其中显示了用户的当前位置 @Override public void onLocationChanged(Location location) { mLastLocation = location; if (currLocationMarker != null) { currLocationMarker.remove(); } //Place current location marker

我制作了一个android应用程序,其中显示了用户的当前位置

@Override
    public void onLocationChanged(Location location) {
    mLastLocation = location;
    if (currLocationMarker != null) {

        currLocationMarker.remove();
    }

     //Place current location marker
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
    currLocationMarker = mGoogleMap.addMarker(markerOptions);
    mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
}
它用标记给出了我的当前位置,但问题是每当我尝试从当前位置缩小时,在几秒钟内它会再次聚焦到同一位置(当前),所以我无法看到地图上的其他点(标记)


如何在Google Maps中禁用此自动放大功能?

仅在第一次将相机居中于当前位置:

private boolean firstLoad = true;
在您的
onLocationChanged

if (firstLoad) {
    mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
    firstLoad = false;
}

仅在第一次将相机居中于当前位置:

private boolean firstLoad = true;
在您的
onLocationChanged

if (firstLoad) {
    mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );
    firstLoad = false;
}

您应该仅第一次使用animateCamera方法。可以使用布尔值仅调用一次。全局声明布尔值并将其设置为false,一旦调用此方法,将其设置为true,在调用此cameraAnimate方法之前,请检查布尔值是否为false,然后仅使用它。

您应仅首次使用animateCamera方法。可以使用布尔值仅调用一次。全局声明布尔值并将其设为false,一旦调用此方法,将其设为true,然后在调用此cameraAnimate方法之前检查布尔值是否为false,然后仅使用它。

声明全局布尔值标志

boolean isFisrtTime = true;
替换

mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );


声明一个全局布尔标志

boolean isFisrtTime = true;
替换

mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()) , 6.0f) );


您的代码是否在
onMapReady
方法上调用? 如果不考虑把它移到那里。
我想您正在调用
onLocationChanged
中的
animateCamera
,并且每次更新位置并且地图重新聚焦到您的位置时都会调用该代码。

您的代码是否在
onMapReady
方法中调用? 如果不考虑把它移到那里。
我想您正在调用
onLocationChanged
中的
animateCamera
,并且每次更新位置和将地图重新聚焦到您的位置时都会调用该代码。

但是如果我删除它,它将不会聚焦到当前位置。。我想要的是,当地图加载时,它应该以所需的缩放显示当前位置但是,当用户进行缩小时,它不应自动恢复到位置,并且仅在第一次更新时才将相机居中,但如果我删除它,它将不会聚焦到当前位置。我想要的是,当地图加载时,它应以所需的缩放显示当前位置,但当用户进行缩小时,它不应恢复到当前位置位置自动更新,仅在第一次将相机居中