我需要在地图视图中显示多个注释并缩放以显示所有这些注释。我有代码
MKMapRect zoomRect = MKMapRectNull;
int i = 0;
for (Post *post in _allPostsToList) {
if (((post.location2D.latitude == 0.0f)&&(post.location2D.longitude == 0.0f))||(!CLLocationCoordinate2DIsValid(post.location2D))) {
i++;
continue;
}
MyAnnotation *annotation = [[MyAnnotation alloc] initWithpost:post];
annotation.tag = i++;
[mapView addAnnotation:annotation];
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
zoomRect = (MKMapRectIsNull(zoomRect))?pointRect:MKMapRectUnion(zoomRect, pointRect);
}
[mapView setVisibleMapRect:zoomRect animated:YES];
它工作正常,但我还需要一件事,需要地图中心的用户位置蓝色气泡,并显示上述所有注释。这个怎么做。我试过这个
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
MKMapRect zoomRect = mapView.visibleMapRect;
MKMapPoint annotationPoint = MKMapPointForCoordinate(newLocation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
zoomRect = (MKMapRectIsNull(zoomRect))?pointRect:MKMapRectUnion(zoomRect, pointRect);
[mapView setVisibleMapRect:zoomRect animated:YES];
[manager stopUpdatingLocation];
}
它的工作但它没有以用户位置为中心如何做到这一点。谁能解决这个问题