如何围绕MKAnnotation数组居中UIMapView?

时间:2010-10-28 16:23:44

标签: iphone xcode ios

如何将UIMapView围绕array MKAnnotation进行居中?

1 个答案:

答案 0 :(得分:2)

首先从注释数组中找到最小和最大纬度和经度。然后你可以设置区域:

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];