MKMapView に追加したい注釈がいくつかあります (n は通常約 5 である 0-n 項目である可能性があります)。注釈を追加することはできますが、画面上のすべての注釈が一度に収まるようにマップのサイズを変更したいのですが、その方法がわかりません。
見てきた-regionThatFits:
けどどうしようか迷ってます。これまでに得たものを示すために、いくつかのコードを投稿します。これは一般的に簡単な作業だと思いますが、これまでのところ MapKit に少し圧倒されているように感じています。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
location = newLocation.coordinate;
//One location is obtained.. just zoom to that location
MKCoordinateRegion region;
region.center = location;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta = 0.015;
span.longitudeDelta = 0.015;
region.span = span;
// Set the region here... but I want this to be a dynamic size
// Obviously this should be set after I've added my annotations
[mapView setRegion:region animated:YES];
// Test data, using these as annotations for now
NSArray *arr = [NSArray arrayWithObjects:@"one", @"two", @"three", @"four", nil];
float ex = 0.01;
for (NSString *s in arr) {
JBAnnotation *placemark = [[JBAnnotation alloc] initWithLat:(location.latitude + ex) lon:location.longitude];
[mapView addAnnotation:placemark];
ex = ex + 0.005;
}
// What do I do here?
[mapView setRegion:[mapView regionThatFits:region] animated:YES];
}
注意してください、これはすべて、場所の更新を受信したときに発生します...これを行うのに適切な場所かどうかはわかりません。そうでない場合、どこがより良い場所になりますか? -viewDidLoad
?
前もって感謝します。