0

Hi i have 100 annotations in mapview ontap of one of its annotations i should get annotation index related to that. Does anyone have idea about getting tag number for that? Looking for any delegate method does.

enter image description here

Nagarjun
  • 6,557
  • 5
  • 33
  • 51

1 Answers1

1

Found an answer this will return annotation tapped number:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
  NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
  NSLog(@"index no %d",index);
}

The above code will generate random index number each time we tap on annotation.

But need to rewrite code as below

- (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];
    }
}
Nagarjun
  • 6,557
  • 5
  • 33
  • 51