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

标签 ios swift mapkit

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

相关文章:

ios - 将具有透视变换的 UIView 转换为 UIImage

ios - 将自定义 cordova 插件添加到 IBM Worklight 6.1

ios - 在 SceneKit 中移动节点

ios - 用于访问 PHAsset 对象的 URL 信息的同步方法

iphone - 我可以在不使用MDM的情况下在iOS Developer Enterprise Program上使用APNS吗

json - 在 Codable - Swift 中使用 "/"和 "%"

swift - 如何突出显示 UIImageView 中图像的一部分?

ios - map 上的自定义图钉(注释)动画

ios - 使用 Xcode 8+ 和 Swift 3+ 与 MapKit 进行集群

ios - MapKit中沿路线的注释