我正在尝试在 mapView 上与 MKAnnotation 之间重绘多段线,但是只有在我放下图钉后它才会重绘,并且我希望即使在拖动图钉时也能继续重绘线条。
我在 Objective C 中见过这个问题,Seeing MKAnnotation Coordinates During Drag但是,不确定如何在 swift 中做类似的事情。
这里是我创建 pin 的地方,它是一个自定义 mkAnnotation。
self.holeCenterCoordinates = CLLocationCoordinate2DMake(holeX, holeY)
self.centerpin.coordinate = self.holeCenterCoordinates
self.centerpin.draggable = true
self.centerpin.imageName = "mapDragCircle.png"
self.holeMap.addAnnotation(self.centerpin)
})
这是我添加行的地方:
let userToCenter = [self.centerpin.coordinate, manager.location?.coordinate] as! [CLLocationCoordinate2D]
let centerToGreen = [greenCenter2D, self.centerpin.coordinate]
let polyline = MKPolyline(coordinates: userToCenter, count: userToCenter.count)
let polyline2 = MKPolyline(coordinates: centerToGreen, count: centerToGreen.count)
holeMap.add(polyline2)
let overlays = self.holeMap.overlays
holeMap.removeOverlays(overlays)
holeMap.add(polyline)
holeMap.add(polyline2)
最佳答案
当您将图钉拖动到另一个位置时,请获取该新图钉位置的纬度和经度,然后首先清除旧的多段线并使用新图钉位置绘制新的多段线。
关于swift - 拖动 SWIFT 期间的 MKAnnotation 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45831597/