1

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.

barndog
  • 6,975
  • 8
  • 53
  • 105

2 Answers2

2

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

EricS
  • 9,650
  • 2
  • 38
  • 34
  • Ah that's so dumb. It seems to set to different zoom levels which is just archaic. I guess the solution is to use the Google Maps iOS SDK inside a webview or something. – barndog Jan 26 '13 at 05:25
  • Google has announced a "real" iOS map SDK that doesn't use a webview, but I don't know if it's shipping yet. File a bug with Apple anyway, though. Maybe if they get enough bug reports they'll fix this one day. It's very annoying. – EricS Jan 26 '13 at 05:28
  • I actually ended up using this: https://github.com/mladjan/GoogleMapsOverlayiOS/blob/master/GoogleMapsiOS6Demo/TileOverlayView.m – barndog Jan 26 '13 at 06:52
2

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.

Craig
  • 8,093
  • 8
  • 42
  • 74