[英]How to set Zoom In and Zoom out in Google ios sdk map using Button
我第一次使用 GoogleMaps,想知道我应该如何在 +/- 按钮的帮助下在 GoogleMap 上实现放大和缩小......我已经设置了 GmsCameraPosition 但不清楚如何放大和缩小使用按钮...我必须按按钮,然后在那里使用我正在使用的操作,如下所示
-(void)zoomOutMapView:(id)sender
{
for (CGFloat i= 10; i<=15; i++) {
[mapView animateToZoom:i ];
[mapView setMinZoom:10 maxZoom:15];
}
}
-(void)zoomInMapView:(id)sender
{
for (CGFloat i= 10; i<=15; i--)
{
[mapView animateToZoom:i ];
[mapView setMinZoom:10 maxZoom:15];
}
}
创建一种用于放大/缩小GmsCameraPosition
常用方法,并在您的GmsCameraPosition
创建一种常用的CGFloat
。
例如
在您的ViewDidLoad
CGFloat currentZoom = 10.0f;
创建通用方法,如
-(Void)ZoominOutMap:(CGFloat)level
{
camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude
zoom:level];
self.MapView.camera = camera;
}
如果你按下+
按钮调用
-(void)zoomInMapView:(id)sender
{
currentZoom = currentZoom + 1;
[self ZoominOutMap:currentZoom];
}
如果你按下-
按钮调用
-(void) zoomOutMapView:(id)sender
{
currentZoom = currentZoom - 1;
[self ZoominOutMap:currentZoom];
}
我们有 GMSCameraPosition :聚合所有相机位置参数的类
示例用法:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.mapType = kGMSTypeSatellite;
我们可以使用这个相机对象来设置缩放级别
camera.zoom = 6;
我们也可以再次重新分配相机以进行地图试用:)
这是#ZoomInZoomOut 通过单击#iOS #GoogleMap #Swift 中的按钮的简单方法
step1:使用命令变量来管理缩放,就像波纹管一样
var currentZoom : Float = 10.0
step2:更改按钮的方法/动作内部变量的值
@IBAction func zoomIn(sender : UIButton)
{
self.currentZoom = self.currentZoom + 1
}
@IBAction func zoomOut(sender : UIButton)
{
self.currentZoom = self.currentZoom - 1
}
// you can also directly write mapView.animate method inside above IBAction
func zoomInZoomOutGoogleMap() {
mapView.animate(toZoom: currentZoom)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.