HERE API:Swift. Wierd behaviour : Loops in a route – Creating a route based on GPS trace creates loops. / passthrough waypoints

im trying to create a route that follows a gps trace i provide.
The gps trace is cleaned up and it has no loops in it and is in correct order.
I checked it with other services.
It has 1920 points.
You can find the trace here GPX File.
Sadly if i create a route based on provided sdk example (github) i get loops in my path.

I was hoping you could help me to solve following problems:

  1. how do i avoid loops while creating route by using HERE ios Swift SDK

  2. how do i set route options is such way to follow provided point array and not create a fastest or balanced route.

Since i could not find those functions in Ios sdk i used additional REST API to filter the route a bit to remove all points that were not matched correctly according to here maps… before drawing the route.. ie everything with low probability, warnings, big distance to the road… yet the result is still not good. Here is a cleaned up file.. the file is being created after the original was maped / run once through HERE Maps. In this file all points that have low confidence or produce warnings or have big distance to original points .. are removed. This is the one i use to create a route and it still have the same issues like loops and weird turns.

Cleaned up GPX file

Thank you very much in advance!
BR.

So far i have this code:

private lazy var router = NMACoreRouter()



 @objc func do_routing_stuff( gps_trace :[NMAWaypoint]) {
    var stops = [Any]()
    stops = gps_trace
    

    let routingMode = NMARoutingMode(routingType: .fastest,
                                     transportMode: .car,
                                     routingOptions: .avoidHighway)
    
    // Trigger the route calculation
           router.calculateRoute(withStops: stops ,
                                      routingMode: routingMode)
           { [weak self] routeResult, error in
               guard error == .none else {
                   self?.showMessage("Error:route calculation returned error code (error.rawValue)")
                   return
               }

               guard let result = routeResult, let routes = result.routes, routes.count > 0 else {
                   self?.showMessage("Error:route result returned is not valid")
                   return
               }

               // Let's add the 1st result onto the map
               self?.route = routes[0]
               self?.updateMapRoute(with: self?.route)

              // self?.startNavigation()
           }
    
}

private func updateMapRoute(with route: NMARoute?) {
    // remove previously created map route from map
    if let previousMapRoute = mapRoute {
        mapView.remove(mapObject:previousMapRoute)
    }
    
    guard let unwrappedRoute = route else {
        return
    }
    
    mapRoute = NMAMapRoute(unwrappedRoute)
    mapRoute?.traveledColor = .clear
    _ = mapRoute.map{ mapView?.add(mapObject: $0) }
    
    // In order to see the entire route, we orientate the
    // map view accordingly
    if let boundingBox = unwrappedRoute.boundingBox {
        geoBoundingBox = boundingBox
        mapView.set(boundingBox: boundingBox, animation: .linear)
    }
}

enter image description here
enter image description here

in comparison same route presented with leaflet maps.

pic4

enter image description here

Source: Swift