Да, это возможно.Сначала необходимо добавить наблюдателя в каждый вид annotationView, чтобы определить, когда пользователь выбирает аннотацию.Сначала вы должны добавить:
static NSString * const GMAP_ANNOTATION_SELECTED = @"gMapAnnotationSelected";
в начало вашей реализации (прямо под @implementation).Затем вы должны добавить наблюдателя для каждого 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;
Затем добавьте следующую функцию в тот же файл, который вызывается при выборе annotationView:
- (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
MKMapViewDelegate