首页 > 解决方案 > 避免地图自动缩小android

问题描述

我在安卓中使用地图。这是我的 OnLocationChanged 方法,我的应用程序工作正常,但我正在缩放我的地图,它会在几秒钟后自动缩小……我在我的方法中使用上面的 MoveCamera。我在 Android Studio 中使用 MapsActivity 默认值。

public void onLocationChanged(Location location) {
        mCurrentLocation = location;
        if (mCurrLocationMarker != null) {
            mCurrLocationMarker.remove();
            //Toast.makeText(context, "Location Not Found.", Toast.LENGTH_SHORT).show();
        }

        //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_MAGENTA));
        mCurrLocationMarker = mMap.addMarker(markerOptions);


        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));


    }

标签: androidgoogle-mapsdictionary

解决方案


您的地图不会自动缩小。它缩小了,因为您为它编写了代码

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));

这在每次 onLocationChanged 和缩放时都有效。如果您想将相机移动到新位置但不想缩放,您可以尝试 CameraUpdateFactory 的 newLatLngBounds 功能


推荐阅读