How can I center a UIMapView
around an array
of MKAnnota开发者_开发知识库tion
?
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];
精彩评论