2012-01-27 7 views
2

私のviewDidLoad:の方法では、いくつかのピン/マーカー/注釈を使用した車両数の異なる場所を表示する方法です。iPhoneで地図ビューからピン/マーカーを隠す方法

私が知りたいのは、ユーザーが車を1つしか選択しないと、他のピン/マーカーを隠すことができないということです。

可能ですか?

どうすればよいですか?

答えて

2

はい、可能です。まず、各annotationViewにオブザーバを追加して、ユーザがアノテーションを選択したときを検出する必要があります。まず、追加する必要があります。

static NSString * const GMAP_ANNOTATION_SELECTED = @"gMapAnnotationSelected"; 

を実装(右@implementation以下)の先頭に。その後、各annotationViewにオブザーバを追加する必要があります。
How to detect AnnotationView selected
MKMapViewDelegate:見て、より多くの情報については

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)localContext { 
char *actionCharStr = (char*)localContext; 
NSString *action = [NSString stringWithCString:actionCharStr encoding:NSStringEncodingConversionAllowLossy]; 

if ([action isEqualToString:GMAP_ANNOTATION_SELECTED]) { 
    BOOL annotationSelected = [[change valueForKey:@"new"] boolValue]; 

    CustomAnnotationView *customAnnotationView; 
    if (annotationSelected) { 
     currentAnnotationView = (CustomAnnotationView*)object; 
     //Go through each annotation in [yourMap annotations] and remove from map if not equal to [currentAnnotationView annotation] 
    } else { 
     currentAnnotationView = (CustomAnnotationView*)object; 
     //Add the annotations back once the annotation is no longer selected  
    } 
}} 

:次にannotationViewが選択されたときに呼び出される同じファイルに以下の機能を追加し

-(MKAnnotationView *)mapView:(MKMapView *)localMapView viewForAnnotation:(id<MKAnnotation>)annotation 

//Create your custom annotation called annotationView 

[annotationView addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:(void*)("gMapAnnotationSelected")]; 

return annotationView; 

:これはによって行われます

関連する問題