我找到了一个名为setLatLngBoundsForCameraTarget的android方法。但找不到ios。有什么想法吗?我想滚动到特定的界限。用户无法滚出已定义的界限
答案 0 :(得分:2)
iOS的等效方法是setCameraTargetBounds。您可以按以下方式使用它:
GMSCoordinateBounds *gmsBounds = [[GMSCoordinateBounds alloc]
initWithCoordinate:bounds.northWest
coordinate:bounds.southEast];
[self.mapView setCameraTargetBounds:bounds];
此外,您可能希望通过执行以下操作来设置最低缩放级别:
[self.mapView setMinZoom:15 maxZoom:23];
答案 1 :(得分:0)
试试这个:
let camera = GMSCameraPosition.camera(withLatitude: -33.8683,
longitude: 151.2086,
zoom: 16)
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
答案 2 :(得分:0)
我使用了cameraTargetBounds但对我没用。然后我用了
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
var latitude = position.target.latitude;
var longitude = position.target.longitude;
if (position.target.latitude > bounds.northEast.latitude) {
latitude = bounds.northEast.latitude;
}
if (position.target.latitude < bounds.southWest.latitude) {
latitude = bounds.southWest.latitude;
}
if (position.target.longitude > bounds.northEast.longitude) {
longitude = bounds.northEast.longitude;
}
if (position.target.longitude < bounds.southWest.longitude) {
longitude = bounds.southWest.longitude;
}
if (latitude != position.target.latitude || longitude != position.target.longitude) {
var l = CLLocationCoordinate2D();
l.latitude = latitude;
l.longitude = longitude;
mapView.animateToLocation(l);
}
}
它有效。