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.
Asked
Active
Viewed 995 times
0
-
means you want to assign unique tag to every annotation? – Ronak Chaniyara Jan 12 '16 at 10:29
-
Add code snippet where you adding annotation to MapView. – Ronak Chaniyara Jan 12 '16 at 10:36
-
i don't want to assign. I already displaying annotations need to get index value for that if user clicking annotations. – Nagarjun Jan 12 '16 at 14:46
1 Answers
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