Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an MKAnnotation is selected on a map?

I have a really simple question: how can I check if an MKAnnotation is selected on a map?

I can't see a selected like (GET) property.

I hope the solution would not be by triggering selected/deselected events and store its result in a property and check them if I need. There must be a more straightforward one.

Thanks very much!

like image 967
Tom Avatar asked Dec 11 '22 15:12

Tom


2 Answers

Check out -[MKMapView selectedAnnotations].

like image 98
incanus Avatar answered Jan 13 '23 00:01

incanus


Making use of the delegate method of MKMapView didSelectAnnotationView: use can get the event MKAnnotation Selected

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    // Annotation is your custom class that holds information about the annotation
    if ([view.annotation isKindOfClass:[Annotation class]]) {
        Annotation *annot = view.annotation;
        NSInteger index = [self.arrayOfAnnotations indexOfObject:annot];
    }
}

Hope it will help you.

like image 25
Gaurav Rastogi Avatar answered Jan 13 '23 00:01

Gaurav Rastogi