在我的应用程序中,我试图阻止用户能够“自由”滚动 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/