java - 锁定 map Activity

标签 java android google-maps scroll locking

在我的应用程序中,我试图阻止用户能够“自由”滚动 map Activity ,我希望显示内容锁定在某些特定坐标中,但困难的部分是将其与相机地理定位(GPS)跟踪用户。

例如,我可以尝试将移动相机添加到 onLocationChanged 中,这会将相机锁定在用户每次移动时我想要的区域,但这不是我想要的,我只想重置相机,如果用户在我不希望他看到的区域中滚动,如果您正在浏览华盛顿 map ,我希望如果用户前往巴尔的摩拉等地时重置相机。

 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)));

最佳答案

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

正如这里提到的: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);

关于java - 锁定 map Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54891895/

相关文章:

java - Android 应用程序在模拟器和 Nexus 10 中不断崩溃

android - Djinni:我可以将接口(interface)定义为在所有环境中都可实现吗?

javascript - React.js,在哪里放置谷歌地图API查询?

java - 如何从 JPanel 组件(例如动态创建的下拉列表、文本字段)获取值

java - Vaadin 动画,使用 Valo 主题淡出和隐藏

java - 枚举内部类

javascript - Google Maps API 中的自定义 InfoWindow 大小/指针位置

java - Set 中的 Get 和 Set 方法

android - 动画后更新布局

javascript - 为什么谷歌地图信息窗口有滚动条