我發現這個解決方案是最可靠的和建議的@Anna它以及所以它可能是一個確定的溶液。
這是我的方法(如遺傳MKMapView
- (void)fitAnnotationsKeepingCenter {
CLLocation *centerLocation = [[CLLocation alloc]
initWithLatitude:self.centerCoordinate.latitude
longitude:self.centerCoordinate.longitude];
// starting distance (do not zoom less than this)
CLLocationDistance maxDistance = 350;
for (id <MKAnnotation> vehicleAnnotation in [self annotations]) {
CLLocation *annotationLocation = [[CLLocation alloc] initWithLatitude:vehicleAnnotation.coordinate.latitude longitude:vehicleAnnotation.coordinate.longitude];
maxDistance = MAX(maxDistance, [centerLocation distanceFromLocation:annotationLocation]);
}
MKCoordinateRegion fittedRegion = MKCoordinateRegionMakeWithDistance(centerLocation.coordinate, maxDistance * 2, maxDistance * 2);
fittedRegion = [self regionThatFits:fittedRegion];
fittedRegion.span.latitudeDelta *= 1.2;
fittedRegion.span.longitudeDelta *= 1.2;
[self setRegion:fittedRegion animated:YES];
}
嘗試下面的我的方法實現的:獲取到來自用戶的位置的註釋的最大距離然後使用MKCoordinateRegionMakeWithDistance設置集中在用戶的區域緯度/距離爲maximumDistance * 2的位置 – Anna 2014-10-18 11:52:28
這是一個好主意,我昨天也得出了相同的結論,但我不確定'MKCoordinateRegionMakeWithDistance'的變量,因爲他們同時使用了'latitudinalMeters'和'longitudinalMeters '我現在只是設置爲相同的,但我不確定你可以輕鬆完成,我會在幾分鐘後發佈我的方法。「 – 2014-10-18 12:55:58
是的,您可以將兩者作爲相同的值傳遞,地圖視圖將根據視圖的比例和可以顯示的縮放級別自動進行調整。 – Anna 2014-10-18 15:18:34