我有几个要添加到我的MKMapView的注释(它可以是0-n个项目,其中n通常约为5)。我可以很好地添加注释,但是我想立即调整地图的大小以适合屏幕上的所有注释,而且我不确定该怎么做。
我一直在看,-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?
提前致谢。
缥缈止盈
翻翻过去那场雪
相关分类