我可以为用户设置有限的区域以在谷歌地图上显示。设置下面的代码后,谷歌地图不会移动到在 Android 中使用以下代码定义的这个区域之外:-
final LatLngBounds ADELAIDE = new LatLngBounds(
new LatLng(25.27, 93.46), new LatLng(27.05, 95.19));
// Constrain the camera target to the Adelaide bounds.
mMap.setMinZoomPreference(6.0f);
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.05839, 94.45399), 6.0f));
现在我正在尝试实现相同的功能来限制 Swift 中谷歌地图区域的用户,但没有像setLatLngBoundsForCameraTarget
.
我试过下面的代码: -
let southWest = CLLocationCoordinate2DMake(25.27,93.46)
let northEast = CLLocationCoordinate2DMake(27.05,95.19)
let bounds = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let cameraBounds = googleMapView.camera(for: bounds, insets: UIEdgeInsets.zero)
googleMapView.camera = cameraBounds!
但这不起作用。用户仍然可以在此范围之外移动。请帮忙。提前致谢。