我正在开发一个跟踪器应用程序,我设法从服务器提取一些数据并更新其他用户的所谓跟踪。但我有这个标记.person,它出现在每一步上。我该如何删除它?
折线是这样绘制的:
private func updateOnlineTrackOnMap() {
let locations = self.track?.points?.map { $0.location } ?? []
guard locations.count >= 2 else { return }
mapView.drawPolyline(withLocations: locations)
mapView.setMark(.person, to: locations.last!.coordinate)
}
但是mapView.removeMark(.person)不起作用。
最佳答案
好的,有一些自定义方法。我已经成功地做到了这样的技巧:
if let oldAnnotation = self.drawer.oldAnnotation {
mapView.removeAnnotation(oldAnnotation)
}
let annotation = MKPointAnnotation()
annotation.coordinate = locations.last!.coordinate
annotation.title = "Speed"
let speed = locations.last!.speed * 3.6
annotation.subtitle = String(format: "%.2f km/h", speed)
mapView.addAnnotation(annotation)
mapView.selectAnnotation(annotation, animated: false)
oldAnnotation = annotation
mapView.drawPolyline(withLocations: locations)
只有一个全局变量来存储当前注释坐标。然后在mapView :viewFor: 中我写了这样的东西:
if annotation is MKPointAnnotation {
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "Online")
annotationView.image = rotatedArrow
annotationView.canShowCallout = true
return annotationView
}
关于ios - 如何快速删除标记的 "trace",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49740460/