How can I get a finer grained span in my MKMapView

僤鯓⒐⒋嵵緔 提交于 2019-12-20 03:42:27

问题


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];

and here is my 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

I get this:

It is zoomed way out. If I look at the MKMapView's region the latitudeDelta i 3.54981 and the longitudeDelta is 3.51562.

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.

NOTE: the mapview pinch zooms just fine to whatever span I want.


回答1:


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];



回答2:


Have you tried on the device? Sometimes I have more control on the zoom level on the device than on the simulator.



来源:https://stackoverflow.com/questions/14760390/how-can-i-get-a-finer-grained-span-in-my-mkmapview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!