锁定地图 activity

lock map activity

在我的应用程序中,我试图阻止用户在地图 activity 周围滚动 "free",我希望显示内容锁定在某些特定坐标中,但困难的部分是将其与相机地理定位 (GPS) 跟随用户的能力联系起来。

例如,我可以尝试向 onLocationChanged 添加一个移动摄像头,这将在每次用户移动时将摄像头锁定在我想要的区域,但这不是我想要的,我只想重置如果用户在我不想让他看到的区域滚动,如果您正在浏览华盛顿地图,我希望在用户去巴尔的摩时重置相机。

 LatLng Washington = new LatLng(38.9150303, -77.1655794);
 public void onLocationChanged(Location location) {
            LatLng me = new LatLng(location.getLatitude(),location.getLongitude());
            //LOCK CAMERA
            mMap.moveCamera(CameraUpdateFactory.newLatLng(Washington));
            //Marker Position
            if (null != currentMarker) {
                currentMarker.remove();
            }
            currentMarker = mMap.addMarker(new MarkerOptions().position(me).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

如果您希望用户能够移动地图但仅限于给定区域,地图会为您提供该选项。

如此处所述:Restricting the user's panning to a given area

private GoogleMap mMap;
// Create a LatLngBounds that includes the city of Adelaide in Australia.
private LatLngBounds ADELAIDE = new LatLngBounds(
  new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
// Constrain the camera target to the Adelaide bounds.
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);