How to recompute Route in Sygic

341 Views Asked by At

my issue is simple I compute a primary route and I added it to Sygic MapView. I defined the startWay point and also the the end point. It works perfectly. But when I try to change to the alternative route when I started the navigation It can't recalculate perfectly the new route. I Used the

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

to detect changes in my position and compute the route every time but I think is not the best choice:

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
}
0

There are 0 best solutions below