Show annotation title automatically
Asked Answered
C

2

15

I'm trying to display the annotation title automatically instead of displaying it on tap. I used the below code to display annotation and make it center on map.

self.ann.setCoordinate(currentLocation2D)
self.ann.title = "Title"
self.ann.subtitle = "Subtitle"
self.mapView.addAnnotation(self.ann);

self.span = MKCoordinateSpanMake(0.005, 0.005)
self.region = MKCoordinateRegion(center: currentLocation2D, span: self.span)
self.mapView.setRegion(self.region, animated: true)

I get to see the title, subtitle and CalloutAccessoryView when I tap the annotation but couldn't able to display it automatically.

Cordiform answered 28/1, 2015 at 17:0 Comment(0)
V
29

You can use it by using selectAnnotation and use the mapview.annotations array, which contains all your annotations which you have on your map.

let yourAnnotationAtIndex = 0
mapView.selectAnnotation(mapView.annotations[yourAnnotationAtIndex], animated: true)
Vercelli answered 28/1, 2015 at 18:23 Comment(2)
It is add title for 1 annotation, how to show title for all annotations?Tericaterina
@DuyenHangKim did you find the solution ?Pella
S
1
mapView.selectAnnotation(mapView.annotations[0], animated: true)
Strapper answered 2/7, 2017 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.