2016-11-14 3 views
0

Mapbox SDK mit swift 3.0 zeichnet keine Polylinie.Mapbox iOS SDK Polylinie, swift 3

(Swift 2.3 funktioniert gut)

Swift 3-Version:

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) 

In Abschluss-Handler-Methode:

var rectangle: MGLPolyline? 

    var coordsArrayValues = coordinatesArray 

    // draw a route 

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

    if let rectangle = rectangle { 
     complection(rectangle) 
    } 

Hier ist, was Debugger sagt in etwa MGLPolyline und coordsArrayValues: (lldb) po coordsArrayValues ​​ ▿ 8 Elemente ▿ 0: CLLocationCoordinate2D - Breite: 37,609333999999997 - Länge: 55,750295000000001 ▿ 1: CLLocationCoordinate2D - Breite: 37,609400999999998 - Länge: 55,750410000000002 ▿ 2: CLLocationCoordinate2D - Breite: 37,609442999999999 - Länge: 55,750495000000001 ▿ 3: CLLocationCoordinate2D - Breite: 37,609763000000001 - Länge: 55,751038999999999 ▿ 4: CLLocationCoordinate2D - Breite: 37,609966999999997 - Länge: 55,751409000000002 ▿ 5: CLLocationCoordinate2D - lati tude: 37,61- Länge: 55,751694000000001 ▿ 6: CLLocationCoordinate2D - Breite: 37,610168000000002 - Länge: 55,751823999999999 ▿ 7: CLLocationCoordinate2D - Breite: 37,610219999999998 - Länge: 55,751918000000003,

.

Später Ich nenne es:

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

In Viewcontroller wird es einfach als Anmerkung hinzugefügt:

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

Können Sie den Code hinzufügen, wo Sie den Wert der Polylinie festlegen und showRoute() aufrufen? – picciano

+0

@picciano, der Wert der Polylinie wurde mit Rechteck hinzugefügt und dann in den Beendigungshandler gesetzt. später bewegt es sich einfach in die Ansicht wie folgt: self? .routeService.getRoute (coordinatesArray: Koordinaten, complection: {[weak self] Polylinie in self? .output.showRoute (Polylinie: Polylinie) }) –

Antwort

0

Fest mit pod-Update (von MapBox 3.3.5 bis 3.3.6-Version) .