自动显示注释标题

Show annotation title automatically

我正在尝试自动显示注释标题,而不是在点击时显示。我使用下面的代码来显示注释并使其在地图上居中。

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)

当我点击注释但无法自动显示时,我可以看到 titlesubtitleCalloutAccessoryView

您可以通过 selectAnnotationmapview.annotations 数组来使用它,其中包含您在地图上的所有 annotations

let yourAnnotationAtIndex = 0
mapView.selectAnnotation(mapView.annotations[yourAnnotationAtIndex], animated: true)
mapView.selectAnnotation(mapView.annotations[0], animated: true)