iOS SDK 6 MKMapKit Behavior

A while ago, we updated our mobile app to be compatible with iOS 6 and iPhone 5. While we were working with the latest Xcode that comes with SDK 6, we found a strange behavior in MKMapKit’s regionThatFits method.

In MKMapView,  a region is an area defined with a lat/long coordinate as the center and a span to specify the distance it covers in lat/long delta. Depending on the dimensions of the MKMapView, the region specified may not fit into the view properly.  So there exists a handy method “regionThatFits” which takes a region as an argument and returns a new region that will include the region you pass in and fits properly in the aspect ratio of the MKMapView. In SDK 5, if the region specified is very tiny, which means the MKMapView’s zoom level can’t support it, the regionThatFits method used to return a minimal region that it can zoom in to. However, with the recent SDK 6 release, the “regionThatFits” method returns a region that the map cannot properly zoom to when you give it a tiny input.

In order to prove this finding, we have come up with a simple prototype an app to perform the following steps:

  1. Create a MKMapView in an app
  2. Call MKMapView’s regionThatFits method with a tiny region and output the returned region from regionThatFits. In our prototype,
    MKCoordinateRegion region = {{37.787096, -122.391},{1.14441e-05, 9.91821e-05}};
    MKCoordinateRegion zoomedRegion = [mapView regionThatFits:region];
  3. Call MKMapView’s setRegion method with the region returned from regionThatFits
    [mapView setRegion:zoomedRegion animated:YES];
  4. Inspect the MKMapView’s current region and compare with the region returned from regionThatFits. Notice the current MKMapView’s region is larger than the region returned from regionThatFits!
In this prototype app, we have created a MKMapView with two buttons and two labels. One of the button zooms the map into a region that works, and another button which zooms into a tiny region that can reproduce the issue (which regionThatFits supposes to return a region that fits in MKMapView). One of the labels indicates the region returned from regionThatFits, and another label that indicates the MKMapView’s region after calling setRegion with the region returned from regionThatFits so that you can compare the before and after value are DIFFERENT. We also include a iOS version label to indicate the current iOS version since this issue only happens in iOS 6. And here are the screenshots of the result.

Here are the results’ screen shots in the order of (Left to right): iOS 5 with a normal region, iOS 5 with a tiny region, iOS 6 with a normal region, and iOS 6 with a tiny region. Notice the difference in the last one.

We have filed a bug report to Apple’s iOS SDK team. Hopefully they can address this issue soon, although we don’t rely heavily on regionThatFits returned region to do any computation at this point.

We hope every mobile developer is having fun with the latest Apple Maps! If anyone has insight about this issue, please leave us a comment.

 

Discussion