Search code examples
here-api

Route Via Intermediate Waypoint - Passing a list of coordinates in via parameter


I need to pass a list of coordinates within parameters in via parameter, but i don't find the way. This is an example with only one pair of coordinates(lat, lng):

function calculateRoute (platform) {
  var router = platform.getRoutingService(null, 8),
    routeRequestParams = {
      routingMode: 'fast',
      transportMode: 'truck',
      origin: '36.87689,-2.44138',
      destination: '36.69630,-4.47968',
      via: '38.99112,-1.86902', //LIST HERE!!!
      return: 'polyline'
    };

  router.calculateRoute(
    routeRequestParams,
    onSuccessRoute,
    onError
  );
}

The url I'm hoping to get is like this:

https://router.hereapi.com/v8/routes?apikey=
{API_KEY}&routingMode=fast&transportMode=truck&origin=36.87689,-2.44138&via=38.99112,-1.86902&via=37.95862,-1.15538&destination=36.69630,-4.47968&return=polyline

As you can see via is repeat in the URL.

Many thanks!


Solution

  • The JavaScript API does not (yet) support multiple routing waypoints with regards to the Routing v8 API, meaning, it does not support passing a list of coordinates to the via parameter.

    So your best bet is to target the Routing v8 REST API directly, like follow, and build a polyline out of the response:

    # Note: line breaks and spaces are for readability only (they need to be removed)
    
    https://router.hereapi.com/v8/routes?
      origin=52.550464,13.384223
      &transportMode=car
      &destination=52.477545,13.447395
      &via=52.529791,13.401389
      &via=52.513079,13.424392
      &via=52.487581,13.425079
      &apikey={YOUR_API_KEY}