2011-07-04 20 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

あなたはズームインとして、あなたはより詳細な情報を取得するので、私はそれらをクラスタリングするでしょう。私はそのように地図に数千を置くと、それは治療を働かせます。あなたがそれを検索すると、地図ピンクラスタリングに関する多くの情報があります。

ここには1つのcommercial option(接続していない、使用していない)がありますが、周りを見回すと、それを自分で実装する方法についての多くの情報が表示されます。

関連する問題