设置MKMapView的缩放级别 [英] Setting the zoom level for a 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屋!