如何显示和滚动 google 地图的特定视图范围?我们看不到和滚动的地图的其他部分
How can I show & scroll particular bound of view for google map? other part of map we can't see and scroll
我为 android 找到了一个名为 setLatLngBoundsForCameraTarget 的方法。但找不到 ios。对此有任何想法吗?我想滚动到特定的范围。用户无法滚动出已定义的边界
试试这个:
let camera = GMSCameraPosition.camera(withLatitude: -33.8683,
longitude: 151.2086,
zoom: 16)
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
我使用了 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);
}
}
而且有效。
iOS 等效方法是 setCameraTargetBounds。您可以按如下方式使用它:
GMSCoordinateBounds *gmsBounds = [[GMSCoordinateBounds alloc]
initWithCoordinate:bounds.northWest
coordinate:bounds.southEast];
[self.mapView setCameraTargetBounds:bounds];
此外,您可能想要设置最小缩放级别,方法是:
[self.mapView setMinZoom:15 maxZoom:23];
我为 android 找到了一个名为 setLatLngBoundsForCameraTarget 的方法。但找不到 ios。对此有任何想法吗?我想滚动到特定的范围。用户无法滚动出已定义的边界
试试这个:
let camera = GMSCameraPosition.camera(withLatitude: -33.8683,
longitude: 151.2086,
zoom: 16)
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
我使用了 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);
}
}
而且有效。
iOS 等效方法是 setCameraTargetBounds。您可以按如下方式使用它:
GMSCoordinateBounds *gmsBounds = [[GMSCoordinateBounds alloc]
initWithCoordinate:bounds.northWest
coordinate:bounds.southEast];
[self.mapView setCameraTargetBounds:bounds];
此外,您可能想要设置最小缩放级别,方法是:
[self.mapView setMinZoom:15 maxZoom:23];