iosswiftxcode9here-apiturn-by-turn

HERE Maps SDK iOS Swift 4 turn by turn navigation takes too long to start


There is scarce documentation and resources available on SO about HERE Maps Mobile-SDK, so I hope somebody can help us out.

We have developed turn by turn navigation in our app (iOS SDK Swift4 XCode9). Everything works great, voices are downloaded properly, route is calculated properly, positioning is started properly and then we call the method:

private func calculateRoute() {
        print("Calculating route")
        // Routing mode
        let routingMode = NMARoutingMode.init(routingType: NMARoutingType.fastest, transportMode: NMATransportMode.car, routingOptions: NMARoutingOption.avoidBoatFerry)
        routeManager.calculateRoute(withStops: [initialCoordinate, destinationCoordinate], routingMode: routingMode) {
            (routeResult: NMARouteResult?, error: NMARoutingError?) in
            if error == nil || error == NMARoutingError.none {
                let mapRoute = routeResult?.routes?.first
                self.route = NMAMapRoute.init(mapRoute!)
                self.gpsMapView.add(mapObject: self.route!)
                self.startNavigation(mapRoute: self.route!)
            } else {
                os_log("Route calculation completed with errors", log: OSLog.default, type: .debug)
                print(error.debugDescription)
            }
        }
    }

private func startNavigation(mapRoute: NMAMapRoute) {
    // Start the turn-by-turn navigation
    navigationManager.startTurnByTurnNavigation(mapRoute.route)
}

Once the start turn by turn navigation method inside navigationManager is called, eventually this callback is called:

func navigationManager(_ navigationManager: NMANavigationManager, didUpdateManeuvers currentManeuver: NMAManeuver?, _ nextManeuver: NMAManeuver?) {
        nextRoadName.text = nextManeuver?.roadName as String?
        displayManeuverImage(icon: currentManeuver?.icon)
}

Once this callback is executed, the navigation works perfectly.

Our problem is that the time spent between the call to:

navigationManager.startTurnByTurnNavigation(mapRoute.route)

And the callback, is randomly long. Sometimes it's 1 seconds (barely ever) and many times it's as long as 2 minutes, which is not acceptable for a production app.

None of our code is getting executed during this wait time, so it must be something internal to HERE Maps-SDK, or some internal issues I'm not aware of.

Does anybody know what is going on here?

Thanks in advance!


Solution

  • This happens because the next maneuver only gets sent when the user starts moving. When the user is stationary the engine cannot find out which direction, accuracy of the position. Once enough movement is detected the maneuvers will be fired.

    You should show the initial maneuver that the engine has after computing the route. Maybe if the user is not moving you can show a toast of the old maneuver to nudge the user to move.