1
A
回答
7
假設你把所有的註解,你可以做以下的數組:
CLLocationCoordinate2D leftTop = CLLocationCoordinate2DMake(-90,180);
CLLocationCoordinate2D rightBottom = CLLocationCoordinate2DMake(90, -180);
for (int i=0; i < [annotations count]; i++) {
id<MKAnnotation> annotation = (id<MKAnnotation>)[annotation objectAtIndex:i];
CLLocationCoordinate2D coord = annotation.coordinate;
if (coord.latitude > leftTop.latitude) {
leftTop.latitude = coord.latitude;
}
if (coord.longitude < leftTop.longitude) {
leftTop.longitude = coord.longitude;
}
if (coord.latitude < rightBottom.latitude) {
rightBottom.latitude = coord.latitude;
}
if (coord.longitude > rightBottom.longitude) {
rightBottom.longitude = coord.longitude;
}
}
MKCoordinateSpan regSpan = MKCoordinateSpanMake(leftTop.latitude-rightBottom.latitude, rightBottom.longitude-leftTop.longitude);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(leftTop.latitude-regSpan.latitudeDelta/2, leftTop.longitude+regSpan.longitudeDelta/2);
regSpan.latitudeDelta = MAX(regSpan.latitudeDelta, 0.01);
regSpan.longitudeDelta = MAX(regSpan.longitudeDelta, 0.01);
MKCoordinateRegion reg = MKCoordinateRegionMake(center, regSpan);
if (CLLocationCoordinate2DIsValid(center)) {
[_mapView setRegion:reg animated:YES];
}
相關問題
- 1. 更改MKMapKit MKAnnotation子類中的圖像
- 2. 這裏地圖 - 中心地圖顯示所有標記
- 3. MKAnnotation在地圖視圖上不顯示
- 4. MKMapKit不顯示userLocation
- 5. 設置縮放和中心顯示所有標記 - 顯示在地圖元素
- 6. 如何在MKAnnotation中顯示所選圖像CalloutAccessoryView,swift 2.2
- 7. iOS地圖 - 帶有圖標的MapKit MKAnnotation
- 8. MKAnnotation不顯示相應的圖標
- 9. 地圖註釋顯示所有點的所有圖像/針腳
- 10. iOS - MKMapKit,顯示註釋中用戶位置的地址
- 11. 顯示Google地圖偏離中心
- 12. 在地圖中心顯示點
- 13. 顯示問題的MKAnnotation
- 14. 顏色地圖不顯示所有值
- 15. Bing地圖ShowInfoBox()總是顯示在地圖的中心?
- 16. 顯示在google地圖中parse.com的所有地點
- 17. infoWindow沒有顯示在地圖的中心
- 18. MKAnnotation顯示所有引腳標題不點擊
- 19. 自動顯示MKAnnotation標註
- 20. 顯示顯示所選地址的谷歌地圖
- 21. 縮放以顯示bing地圖中的所有位置
- 22. 突出顯示Android中的所有世界谷歌地圖
- 23. 顯示目錄中的所有圖像
- 24. 顯示Firebase中的所有圖片
- 25. 如何顯示地圖視圖上的所有點?
- 26. 小冊子:如何顯示地圖上的所有圖層?
- 27. Android Google Maps - 如何設置地圖的縮放級別(和中心)以顯示所有地理對象?
- 28. 如何在android中顯示地圖的中心半徑部分
- 29. MVC地圖中的OpenLayers沒有顯示
- 30. 如何更改MKAnnotation的中心點
就像一個魅力。非常感謝 – BlackMouse
爲了節省你的循環,你可以加倍lat_min = [[annotations valueForKeyPath:@「@ min.latitude」] doubleValue]; double lat_max = [[annotations valueForKeyPath:@「@ max.latitude」] doubleValue]; double lon_min = [[annotations valueForKeyPath:@「@ min.longitude」] doubleValue]; double lon_max = [[annotations valueForKeyPath:@「@ max.longitude」] doubleValue]; – bigkm