ここには MapKit を使用するアプリがあり、それにオーバーレイと注釈をいくつか描画します。
それらは表示されますが、最初にマップを移動するか、描画する前に少し拡大/縮小する必要があります。
それに対する修正はありますか?
ここには MapKit を使用するアプリがあり、それにオーバーレイと注釈をいくつか描画します。
それらは表示されますが、最初にマップを移動するか、描画する前に少し拡大/縮小する必要があります。
それに対する修正はありますか?
マップのズームとフィットの注釈のために呼び出すだけです:- [self zoomToFitMapAnnotations:self.mapView];
(void)zoomToFitMapAnnotations:(MKMapView*)aMapView { if([aMapView.annotations count] == 0) return;
CLLocationCoordinate2D topLeftCoord; topLeftCoord.latitude = -90; topLeftCoord.longitude = 180;
CLLocationCoordinate2D bottomRightCoord; bottomRightCoord.latitude = 90; bottomRightCoord.longitude = -180;
for(PlaceMark *annotation in aMapView.annotations) { topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}
MKCoordinateRegion リージョン。region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5; region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // 側面に少し余分なスペースを追加します region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // 側面に少し余分なスペースを追加します
地域 = [aMapView regionThatFits:地域]; [aMapView setRegion:地域アニメーション:YES]; }