我有 2000 注释,并且在地图上显示所有内容都太慢了。如何限制地图上的注释视图? annotationsInMapRect
可能有用吗?如果您需要更多信息,请与我们联系!
MKAnnotationView
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if (![annotation isKindOfClass:[MyAnnotation class]])
{
return nil;
}
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *pinView = [aMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (pinView == nil)
{
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.canShowCallout = YES;
}
else
pinView.annotation = annotation;
MyAnnotation *myAnn = (MyAnnotation *)annotation;
pinView.image = [UIImage imageNamed:myAnn.icon];
return pinView;
}
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
for(MKAnnotationView *annotationView in views)
{
if(annotationView.annotation == mv.userLocation)
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.005;
span.longitudeDelta=0.005;
CLLocationCoordinate2D location=mv.userLocation.coordinate;
region.span=span;
region.center=location;
[mv setRegion:region animated:YES];
[mv regionThatFits:region];
id annotation = annotationView.annotation;
[self performSelector:@selector(selectUserLocation:) withObject:annotation afterDelay:0.5f];
}
}
}