Why MKCoordinateSpan changes?

瘦欲@ 提交于 2019-12-02 18:09:46

问题


When I debug code below, I see that span is changed by mapkit from what I have provided. span2 contains different numbers from what was provided. Why is this happening?

- (void) viewDidLoad
{
    [super viewDidLoad];

    CLLocationCoordinate2D loc;
    loc.latitude = self.atm.lat;
    loc.longitude = self.atm.lon;

    MKCoordinateSpan span1 = MKCoordinateSpanMake(0.05f, 0.05f);
    self.mapView.region = MKCoordinateRegionMake(loc, span1);
    // at this point numbers are not 0.05 anymore
    MKCoordinateSpan span2 = self.mapView.region.span;
// ... more code
}

回答1:


Note that latitude and longitude change differently so square MapView will actually display region with different span values for its coordinates. This is likely to cause your mapview region to have span (slightly?) different from what you set.

In reference for MKMapView's region property there's somewhat relevant phrase:

Changing only the center coordinate of the region can still cause the span to change implicitly. This is due to the fact that the distances represented by a span change at different latitudes and longitudes and the map view may need to adjust the span to account for the new location.




回答2:


A square MapView with identical values for the latitudinal and longitudinal span will almost always experience the change in span indicated above as longitudinal arc-length varies significantly as you move from the equator to either pole. As the latitude approaches +/-90, the longitudinal arc-length approaches 0.

In addition, however, identical span values will also change if the MapView region is not square (as the span only refers to the region actually visible at the time).



来源:https://stackoverflow.com/questions/2537263/why-mkcoordinatespan-changes

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