Mapbox iOS SDK 折线,swift 3

Mapbox iOS SDK polyline, swift 3

带有 swift 3.0 的 Mapbox SDK 不绘制折线。

(Swift 2.3 工作正常)

Swift 3 版本:

for coord in coordsArray! {

                    let lat = coord.array?.first?.double
                    let lon = coord.array?.last?.double

                    let point = CLLocationCoordinate2D(latitude: lat!, longitude: lon!)

                    coordsArrayValues.append(point)
                }
                completionHandler(coordsArrayValues)

在完成处理程序方法中:

var rectangle: MGLPolyline?

    var coordsArrayValues = coordinatesArray

    // draw a route

    rectangle = MGLPolyline(coordinates: &coordsArrayValues, count: UInt(coordsArrayValues.count))

    if let rectangle = rectangle {
        complection(rectangle)
    }

这是调试器在关于 MGLPolyline 和 coordsArrayValues 中所说的: (lldb) po 坐标数组值 ▿ 8个元素 ▿ 0 : CLLocationCoordinate2D - 纬度:37.609333999999997 - 经度:55.750295000000001 ▿ 1 : CLLocationCoordinate2D - 纬度:37.609400999999998 - 经度:55.750410000000002 ▿ 2 : CLLocationCoordinate2D - 纬度:37.609442999999999 - 经度:55.750495000000001 ▿ 3 : CLLocationCoordinate2D - 纬度:37.609763000000001 - 经度:55.751038999999999 ▿ 4 : CLLocationCoordinate2D - 纬度:37.609966999999997 - 经度:55.751409000000002 ▿ 5 : CLLocationCoordinate2D - 纬度:37.610123999999999 - 经度:55.751694000000001 ▿ 6 : CLLocationCoordinate2D - 纬度:37.610168000000002 - 经度:55.751823999999999 ▿ 7 : CLLocationCoordinate2D - 纬度:37.610219999999998 - 经度:55.751918000000003 ,

.

以后我称之为:

self?.routeService.getRoute(coordinatesArray: coordinates, complection: { [weak self] polyline in
            self?.output.showRoute(polyline: polyline)
        })

在ViewController中,它只是作为注释添加:

func showRoute(polyline: MGLPolyline) {
    DispatchQueue.main.async { [weak self] in
        self?.mapView.addAnnotation(polyline)
    }
}

通过 pod 更新修复(从 Mapbox 3.3.5 到 3.3.6 版本)。