1

我有大约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]; 
        }
    }
}
4

0 回答 0