我在这里有一个使用 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(aMapView.annotations 中的 PlaceMark *annotation) { 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; // 在边上添加一点额外的空间
region = [aMapView regionThatFits:region]; [aMapView setRegion:region Animation:YES]; }