自动显示注释标题

Sru*_*mha 13 mkmapview mkannotation swift

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

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)
Run Code Online (Sandbox Code Playgroud)

我能看到的title,subtitleCalloutAccessoryView当我点击的注解,但是可能无法自动显示.

Chr*_*örz 28

您可以通过使用selectAnnotation并使用mapview.annotations数组来使用它,该数组包含您annotations在地图上拥有的所有数据.

let yourAnnotationAtIndex = 0
mapView.selectAnnotation(mapView.annotations[yourAnnotationAtIndex], animated: true)
Run Code Online (Sandbox Code Playgroud)

  • 它是为 1 个注释添加标题,如何显示所有注释的标题? (2认同)