gpt4 book ai didi

ios - 如何快速删除标记的 "trace"

转载 作者:行者123 更新时间:2023-11-30 11:36:15 25 4
gpt4 key购买 nike

我正在开发一个跟踪器应用程序,我设法从服务器提取一些数据并更新其他用户的所谓跟踪。但我有这个标记.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)不起作用。

enter image description here

最佳答案

好的,有一些自定义方法。我已经成功地做到了这样的技巧:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com