设置MKMapView的缩放级别 [英] Setting the zoom level for a MKMapView

查看:1160
本文介绍了设置MKMapView的缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张正确显示的地图,我现在唯一要做的就是在加载时设置缩放级别。有没有办法做到这一点?

I have a map which shows correctly, the only thing I want to do now is set the zoom level when it loads. Is there a way to do this?

谢谢

推荐答案

我发现自己是一个解决方案,这很简单并且可以解决问题。使用 MKCoordinateRegionMakeWithDistance ,以垂直和水平方式设置以米为单位的距离,以获得所需的缩放。当然,当您更新您的位置时,您将获得正确的坐标,或者您可以在启动时直接在 CLLocationCoordinate2D 中指定它,如果这是您需要做的:

I found myself a solution, which is very simple and does the trick. Use MKCoordinateRegionMakeWithDistance in order to set the distance in meters vertically and horizontally to get the desired zoom. And then of course when you update your location you'll get the right coordinates, or you can specify it directly in the CLLocationCoordinate2D at startup, if that's what you need to do:

CLLocationCoordinate2D noLocation;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(noLocation, 500, 500);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];          
[self.mapView setRegion:adjustedRegion animated:YES];
self.mapView.showsUserLocation = YES;

这篇关于设置MKMapView的缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆