4

全新的 Xcode 版本,除了删除大量添加空函数调用的地方外,还引入了一个有趣的问题,即用一段简单的代码绘制大地路径:

func drawPolyline(from startLocation: CLLocation, endLocation:CLLocation) {
    let point1 = startLocation.coordinate
    let point2 = endLocation.coordinate
    var points: [CLLocationCoordinate2D]
    points = [point1, point2]
    var coordinates=points[0]
    let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count:2)
    self.mapView.add(geodesic)
}

编译器抱怨:

'init(coordinates:count:)' 的模糊使用

当我尝试点击给定的选项时,我总是被引导到那条线。我试图清理项目无济于事。

4

2 回答 2

3

在这种情况下MKGeodesicPolyline,将使用UnsafePointerUnsafeMutablePointer使用CLLocationCoordinate2D您定义为点的类型,因此您可能想要:

let geodesic = MKGeodesicPolyline(coordinates: points, count: 2)

苹果开发者:CLLocation

于 2016-07-08T17:36:15.210 回答
0

让测地线 = MKGeodesicPolyline(坐标:&坐标,计数:2)

  • 删除坐标前的“&”符号。这解决了这个问题。
于 2017-05-30T12:41:03.570 回答