0

我的问题很简单,我计算了一条主要路线并将其添加到 Sygic MapView。我定义了起点和终点。它完美地工作。但是当我开始导航时尝试更改为替代路线时,它无法完美地重新计算新路线。我用过

 func navigation(_ navigation: SYNavigation, didUpdate positionInfo: SYPositionInfo?) {

检测我的位置变化并每次计算路线,但我认为这不是最佳选择:

func navigation(_ navigation: SYNavigation, didUpdate positionInfo: SYPositionInfo?) {
        if (mapRoute != nil){
            mapView.remove(mapRoute)
            computeRoute(from: startPointMP, to: endPointMP)
        }
    }

func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate:
    SYGeoCoordinate) {
    let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: "Begin")
    let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: "End")
    let routingOptions = SYRoutingOptions()
    routingOptions.transportMode = .unknown// For other options see SYTransportMode
    routingOptions.routingType = .economic// For other options see SYRoutingType
    routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
}


func routing(_ routing: SYRouting, didComputePrimaryRoute route: SYRoute?) {
    SYNavigation.shared().start(with: route)
    // You might want to put it also on the map
    mapRoute = SYMapRoute(route: route!, type: .primary)
    markerEnd = SYMapMarker(coordinate: endPointMP!, image: UIImage(named: "Arrive")!)
    mapView.add(mapRoute)
    mapView.add(markerEnd)
    mapView.add(markerStart)
    mapView.cameraMovementMode = .free
}
4

0 回答 0