锁定地图活动

问题描述 投票:0回答:1

在我的应用程序中,我试图让用户能够在地图活动周围“自由”滚动,我希望显示内容锁定在一些特定的坐标,但困难的部分是将其与相机地理定位的能力连接起来( GPS)跟随用户。

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

 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)));
java android google-maps scroll locking
1个回答
2
投票

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

如上所述: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);
© www.soinside.com 2019 - 2024. All rights reserved.