I have an app that on startup centers on a specific location.
//Calculate and set new center point
CLLocationCoordinate2D zoomLocation = CLLocationCoordinate2DMake(<some lat>,<some long>);
MKCoordinateSpan span;
span.latitudeDelta = 0.08;
span.longitudeDelta = 0.08;
//MKCoordinateRegion region = MKCoordinateRegionMake(zoomLocation, span);
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMake(zoomLocation, span)];
[mapView setRegion:region animated:YES];
[self refreshMap];
The call to refreshMap attempts to calculate the bounding box of the map so that I can query into the database for the respective information.
//Calculate map's bounding box
MKMapRect mapRect = [mapView visibleMapRect];
MKMapPoint cornerPointNE = MKMapPointMake(MKMapRectGetMaxX(mapRect), mapRect.origin.y);
CLLocationCoordinate2D upperLeft = MKCoordinateForMapPoint(cornerPointNE);
MKMapPoint cornerPointSW = MKMapPointMake(mapRect.origin.x, MKMapRectGetMaxY(mapRect));
CLLocationCoordinate2D lowerRight = MKCoordinateForMapPoint(cornerPointSW);
if( fabs(upperLeft.longitude) > 80.00 || fabs(lowerRight.longitude) > 80.0) {
return;
}
The issue that I am seeing is that in iOS 6 the lowerRight coordinate is not correctly calculated at app startup and the map data does not get refreshed as the lowerRight.longitude is > 80.0. The upperLeft is correctly calculated.
After the app has finished loading if I pan the map even the slightest the bounding box calculations are correct.
This code works fine in iOS 5.
Is there a callback other than mapView:regionDidChangeAnimated that I could use? The rest of refreshMap is fairly intensive and I do not want to impact panning performance.
TIA
UPDATE
I seem to have found a fix. Instead of doing this
[mapView setRegion:region animated:YES];
I changed the YES to NO
[mapView setRegion:region animated:NO];
and now the lower corner is correctly calculated on app startup.