2011-07-04 109 views
2

我有超過2800個地點放在我的地圖上。 但是,當我把他們的地圖凍結。我什麼都不能做,只能等到所有的註釋數據都可用。如何在不影響MKMapView性能的情況下添加MKAnnotation

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ 
     NSAutoreleasePool *pool_mr = [[NSAutoreleasePool alloc] init]; 

     NSLog(@"mapView:regionDidChangeAnimated:"); 
     NSLog(@"latitude: %f, longitude: %f", regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude); 
     NSLog(@"latitudeDelta: %f, longitudeDelta: %f", regionsMapView.region.span.latitudeDelta, regionsMapView.region.span.longitudeDelta); 

     if (regionsMapView.region.span.latitudeDelta < 0.007) { 
      NSLog(@"SHOW ANNOTATIONS"); 
      NSArray *annotations = [regionsMapView annotations]; 
      AddressAnnotation *annotation = nil; 
      for (int i=0; i<[annotations count]; i++) 
      { 
       NSLog(@"%i", i); 
       annotation = (AddressAnnotation*)[annotations objectAtIndex:i]; 
       [[regionsMapView viewForAnnotation:annotation] setHidden:NO]; 
      } 
     }else { 
      NSLog(@"HIDE ANNOTATIONS"); 
      NSArray *annotations = [regionsMapView annotations]; 
      AddressAnnotation *annotation = nil; 
      for (int i=0; i<[annotations count]; i++) 
      { 
       NSLog(@"%i", i); 
       annotation = (AddressAnnotation*)[annotations objectAtIndex:i]; 
       [[regionsMapView viewForAnnotation:annotation] setHidden:YES]; 
      } 

     } 
    [pool_mr release]; 
} 

而另一種方法是象下面這樣:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation, AddressAnnotation>) annotation {  
    //NSAutoreleasePool *pool5 = [[NSAutoreleasePool alloc] init]; 
    // if it's the user location, just return nil. 
    if ([annotation isKindOfClass:[MKUserLocation class]]){ 
     NSLog(@"MKUserLocation"); 
     return nil; 
    } 
    else { 
     NSLog(@"mapView:viewForAnnotation>>>"); 
     NSLog(@"%@", [annotation markerColor]); 
     NSLog(@"image: %@", [NSMutableString stringWithFormat:@"MKPinAnnotationView_%@.png",[annotation markerColor]]); 
     MKPinAnnotationView *annView=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation markerColor]] autorelease]; 
     //annView.pinColor = MKPinAnnotationColorPurple; 
     UIImage *annotationImage = [[UIImage imageNamed:[NSMutableString stringWithFormat:@"MKPinAnnotationView_%@.png",[annotation markerColor]]] autorelease]; 

     annView.image = annotationImage; 
     annView.animatesDrop = NO; 
     annView.canShowCallout = YES; 
     //annView.draggable = NO; 
     //annView.highlighted = NO; 

     annView.calloutOffset = CGPointMake(-5, 5); 
     return annView; 
    } 

    //[pool5 release]; 
    NSLog(@"<<<mapView:viewForAnnotation"); 

    return nil; 

} 

回答

4

與該號碼的註釋,所以你放大,你會得到更多的細節我就聚集他們。我在那張地圖上放了幾千張,這是一種享受。如果搜索它,有許多關於地圖別針羣集的信息。

這裏有一個commercial option例如(無連接,沒有用),但如果你看看周圍,你會看到大量關於如何實現它自己。

相關問題