tags:

views:

19

answers:

1

How can I center a UIMapView around an array of MKAnnotation?

+1  A: 

First find the minimum and maximum latitude and longitude from your array of annotations. Then you can set the region:

MKCoordinateRegion extents;
extents.center.latitude = (maxLat + minLat)/2.0;
extents.center.longitude = (maxLong + minLong)/2.0;
extents.span.latitudeDelta = (maxLat - minLat);
extents.span.longitudeDelta = (maxLong - minLong);
MKCoordinateRegion fittedRegion = [mapView regionThatFits:extents];
[mapView setRegion:fittedRegion animated:YES];
aBitObvious
Thank you, I hoped there was something built in MKMapView. But ok thanks you again
Christophe Debove