0

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
}
Walid Sassi
  • 185
  • 2
  • 16
  • Why are you trying to compute route after every position change? After you start navigation, the route progress is computed and modified automatically. If it changes because you decided to go different way, then you will get call from SYRoutingDelegate `func routing(_ routing: SYRouting, didFinishRouteRecompute route: SYRoute)`. After that it makes sense to replace old route with new one. Or is there any other reason you would want to do it the way you described? – anonym Nov 26 '18 at 16:21
  • if I understand you, when I go away from my route, I should recompute the new route when func routing(_ routing: SYRouting, didFinishRouteRecompute route: SYRoute). and the new route will those passed in the argument of this method delegate or should I recalculate the route ??? – Walid Sassi Nov 27 '18 at 20:17
  • Yep, that is correct. The route will be automatically recomputed when you go different way than you was supposed to and new route will be passed as an argument in that method. So you don't need to compute new route again. – anonym Nov 27 '18 at 23:24
  • ok, it's work fine – Walid Sassi Nov 28 '18 at 14:20

0 Answers0