show map callout through code in iPhone

2019-07-08 05:42发布

问题:

I have tried several things but am unable to solve it out.

I have 10 custom annotations on the map depending upon the area visible.

Now I have 2 buttons next and previous. Clicking on which the callout of annotation must get displayed.

i.e if i click on next buton then callout of annotation 1 will appear and when i click next again then the callout of first will hide and callout of second will appear.

I have tried out

[self.mapView selectAnnotation:self.nextSelectedAnnotationView.annotation animated:YES]

and

[self.mapView deselectAnnotation:self.selectedAnnotationView.annotation animated:YES];

But the main problem is how to get the annotation here??

I have tried NSArray* selectedAnnotations=self.mapview.annotations to get the annotations array

id annotationView =[selectedAnnotations objectAtIndex:i];
[self.mapView selectAnnotation:annotationView animated:YES];

But no luck :(

Any other way to solve my issue.??

回答1:

it may help you.

 NSArray *selectedAnnotations = mapView.selectedAnnotations;
for(id annotationView in selectedAnnotations) {
    [mapView deselectAnnotation:[annotationView annotation] animated:NO];
}