I need to show the Trip route on the map. To calculate a route based on an imported GeoCoordinates list, I've used the HERE SDK's OfflineRoutingEngine class. The problem is that the route returned by the calculateRoute function resembles a combination of all routes connected. Could someone please help me identify the problem with the code here?
List<Waypoint> waypoints = new ArrayList<>();
waypoints.add(new Waypoint(routePoints.get(0)));
for (int i = 1; i < routePoints.size() - 1; i++) {
Waypoint wp = new Waypoint(routePoints.get(i));
wp.type = WaypointType.PASS_THROUGH;
waypoints.add(wp);
}
waypoints.add(new Waypoint(routePoints.get(routePoints.size() - 1)));
mOfflineRoutingEngine.calculateRoute(waypoints, new CarOptions(), (routingError, routes) -> {
if (routingError != null) {
Log.d(TAG, "showRoute(): Error while calculating a route");
return;
}
// When routingError is null, routes is guaranteed to contain at least one route
if ((routes != null) && (routes.size() > 0)) {
Route route = routes.get(0);
if (mRoutePolyline == null) {
Log.d(TAG, "showRoute(): addPolyline");
// shows routes
mRoutePolyline = new MapPolyline(route.getGeometry(), ROUTE_LINE_WIDTH, mRouteColor);
mMapView.getMapScene().addMapPolyline(mRoutePolyline);
} else {
Log.d(TAG, "showRoute(): updatedPolyline");
// update route
mRoutePolyline.setGeometry(route.getGeometry());
}
} else {
Log.d(TAG, "showRoute(): Error while calculating a route");
}
});
I'm getting the following result as a geometry of a route: enter image description here
If you are trying to import a route from another service or when you have a large number of waypoints that already mark a route path, use the "import route" feature of the HERE SDK:
This code snippet is taken from the documentation.
In your case, the image seems to show multiple waypoints that have to be reached by the
OfflineRoutingEngine. The engine tries to reach all waypoints in the order of the list - so, this might explain the reason of the unexpected look.So, before using the
importRoute()-feature, it may be worth to try if you can achieve a better result by ordering the waypoints. Add the following lines:optimizeWaypointsOrderdefaults to false, but when it is true, the engine will try to find the optimal route to connect all waypoints - ignoring the position in the list.