here-apihere-maps-restheremaps-android-sdk

How to use previosly calculated route in Here Navigation SDK version 4.7.4?


I am using Here SDK version 4.7.4 for the Android navigation app. So, We calculate the route using our web portal and want to use the same route that we calculated(using the web portal by calling here REST API) in the Android Navigation app.

I have searched online for this and unfortunately did not find anything worthful.

Currently, In the Here map Navigation example, It calculates the route using the below lines of code:

Waypoint startWaypoint = new Waypoint(startGeoCoordinates);
Waypoint destinationWaypoint = new Waypoint(destinationGeoCoordinates);

List<Waypoint> waypoints = new ArrayList<>(Arrays.asList(startWaypoint, destinationWaypoint));

routingEngine.calculateRoute(waypoints, new TruckOptions(), calculateRouteCallback);

I want to replace these code by calling another Here SDK method that can return the previously calculated route. And when we start the navigation it should follow the route.


Solution

  • You cannot convert the Route object that you have received from the REST API call to a Java or Kotlin object that the HERE SDK can understand - as JavaScript/JSON vs. Java / Kotlin are not compatible, and most importantly, the Route object cannot be generated on app side from scratch as no constructor is publicly accessible.

    You can only try to create the route again with the same parameters that you have used on your web portal. The results may differ, as it is a new calculation and time and traffic situation may change the route.

    A better solution may be to talk to the HERE support team and ask them to allow creating routes from a given RouteHandle. The route handle uniquely identifies a route and it is just a String representation of a route. The REST API can generate the handle and the HERE SDK can then consume it, in theory ...