swift - 拖动 SWIFT 期间的 MKAnnotation 坐标

标签 swift mkmapview

我正在尝试在 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/

相关文章:

iOS - MKAnnotationView 自定义 UIButton 问题

ios - MKMapView 合法标签显示为 <unlocalized>

ios - iOS6 上 MapKit 的性能问题

ios - Swift 不同的图像进行注释

ios - swift uiview 没有名为 center 的成员

ios - WebView VC Swift 中出现意外的标题

ios - 如何从单元格中检索 detailedText 然后在函数中使用它?

ios - 使用 Swift 4 在 iOS 中将多级 JSON 解码为结构

ios - 如何将 UICollectionView 单元格与 UICollectionView 边界对齐

objective-c - MKMapView 与一个 MKOverlayPathView 会导致 map 模糊