2016-11-14 83 views
0

使用swift 3.0的Mapbox SDK不繪製多段線。Mapbox iOS SDK多段線swift 3

(雨燕2.3優良工程)

斯威夫特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 coordsArrayValues ▿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 - LATI突地:37.61 - 經度: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) 
     }) 

在視圖控制器它只是添加註釋:

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

你可以添加代碼設置折線的值,並調用showRoute()? – picciano

+0

@picciano,多段線的值用矩形添加,然後放入完成處理程序。後來它只是像這樣移動到視圖中:self?.routeService.getRoute(coordinatesArray:coordinates,complection:{[weak self] polyline in self?.output.showRoute(polyline:polyline) }) –

回答

0

與莢更新修復(從Mapbox 3.3.5至3.3.6版本) 。