开发者

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

开发者 https://www.devze.com 2023-01-22 15:38 出处:网络
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:

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

精彩评论

暂无评论...
验证码 换一张
取 消