如何在MKMapView中获得更精细的跨度 [英] How can I get a finer grained span in my MKMapView
问题描述
我正在使用MKMapView并且我正在初始化如下:
I'm using an MKMapView and I'm initializing like this:
homeLocation.latitude = 42.033126;
homeLocation.longitude = -70.168621;
[self.mapView setCenterCoordinate:homeLocation animated:NO];
MKCoordinateRegion viewRegion;
viewRegion.center = homeLocation;
viewRegion.span = MKCoordinateSpanMake(1.7, 1.7);
[self.mapView setRegion:[self.mapView regionThatFits:viewRegion] animated:NO];
这是我的应用
< img src =https://i.stack.imgur.com/c3BLp.jpgalt =在此处输入图像说明>
这很好,除了我的app我需要将它缩小一点。但是当我尝试这个时:
That's fine, except for my app I need to have it zoomed out a tiny bit more. But when I try this:
viewRegion.span = MKCoordinateSpanMake(1.8, 1.8); // use span of 1.8, not 1.7
我明白了:
它缩小了出路。如果我查看MKMapView的区域,latitudeDelta i 3.54981和longitudeDelta是3.51562。
It is zoomed way out. If I look at the MKMapView's region the latitudeDelta i 3.54981 and the longitudeDelta is 3.51562.
如何将我的跨度设置为1.7到3.5之间的值?我希望这个特定的应用程序能够达到2.25左右。
How can I set my span to a value between 1.7 and 3.5? I'd love to hit around 2.25 for this particular application.
注意:mapview捏缩放到任何我想要的范围都可以。
NOTE: the mapview pinch zooms just fine to whatever span I want.
推荐答案
MKCoordinateSpanMake使用度数,1度约69英里。如果你想要更细粒度的设置,请改用MKCoordinateRegionMakeWithDistance。
MKCoordinateSpanMake uses degrees, and 1 degree is about 69 miles. If you want a more fine grained setting, use MKCoordinateRegionMakeWithDistance instead.
CLLocationCoordinate2D homeLocation;
homeLocation.latitude = 42.033126;
homeLocation.longitude = -70.168621;
[self.mapView setCenterCoordinate:homeLocation animated:NO];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance( homeLocation, 200000, 200000);
// 200000 meter is approximately 1.8 degree
[self.mapView setRegion:[self.mapView regionThatFits:viewRegion] animated:NO];
这篇关于如何在MKMapView中获得更精细的跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!