iOS MapView not updating to specified span

535 views Asked by At

I have a map in my iOS application that won't set the visible region to where I'm specifying it.

- (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation*)aUserLocation    
{
    MKCoordinateSpan span;
    span.latitudeDelta = .011932;
    span.longitudeDelta = 0.011242;
    MKCoordinateRegion region;
    region.center = self.mapView.userLocation.coordinate;
    region.span = span;
    [aMapView setRegion:region animated:YES];
}

That's my code and you would assume it would work, it's pretty straightforward and all. However, it sets the visible region to a slightly but noticeable region above what I want. I printed out the span delta values in mapView:regionDidChangeAnimated and the values I got back are:

Span: 0.014576, 0.013733

Which is not what I set it to.

Any thoughts as to why? More than anything, I really want to understand why this is happening and if it's a product of using Apple Maps or it's some wonky thing that I'm doing wrong. Upvote if you wouldn't mind so other people who have this issue can get a fix.

2

There are 2 answers

3
EricS On BEST ANSWER

This has been a problem with MKMapView forever. Setting the region doesn't set the exact region you pass into it.

0
Craig On

Since you're not changing the shape of the map view, no matter what span you give it it has to come out to the ratio. For example it couldn't end up with your target region if you told it you wanted to view something 100 times taller than it is wide. Also, it snaps to a set of preferred zoom levels where the map looks better, I think. So your region is entirely visible, and there may be padding around it if needed.