GuidesAPI Reference
Guides

Re-evaluate route with different options

In this tutorial you will learn how to serve various use cases by requesting the route to be evaluated with a different set of route options than it was computed with.

Common to all of these scenarios is that a routeHandle is requested during the initial calculation, and then a follow-up request with that handle is used to re-evaluate the route. See How to use route handles for how to request and use a routeHandle.

Compute a route without traffic, then request traffic information on the route

Oftentimes you want to compute the route a driver would take if no traffic would influence their route choice, and then evaluate the current traffic situation along that route.

The initial request is only asking for a routeHandle and passing traffic[mode]=disabled:

curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin={YOUR_ORIGIN}&'\
'destination={YOUR_DESTINATION}&'\
'return=routeHandle&'\
'transportMode=car&'\
'traffic[mode]=disabled&'\
'apiKey=YOUR_API_KEY'

The follow-up request is asking for incidents, summary, and dynamicSpeedInfo to get information about the traffic situation:

curl -gX GET 'https://router.hereapi.com/v8/routes/{ROUTE_HANDLE}?'\
'return=polyline,incidents,summary&'\
'spans=incidents,dynamicSpeedInfo,notices&'\
'transportMode=car&'\
'apiKey=YOUR_API_KEY'

The response has various pieces of information we can expose to the user:

  • The summary contains the traffic-based duration.
  • incidents list all traffic incidents along the route.
  • notices inform you if part of the route is blocked by traffic.
  • dynamicSpeedInfo contains information about traffic speed and base speed

Choose a route that other vehicle types would use

Sometimes you want to evaluate how a route computed for one vehicle type would work out for another vehicle type.

For example, you can compute a route for car, and evaluate how a heavy truck could handle it:

curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin=52.551716,13.420443&'\
'destination=52.496361,13.319506&'\
'return=routeHandle&'\
'transportMode=car&'\
'apiKey=YOUR_API_KEY'

The route is then evaluated for a 40t truck:

curl -gX GET 'https://router.hereapi.com/v8/routes/{ROUTE_HANDLE}?'\
'return=polyline,summary&'\
'spans=notices&'\
'transportMode=truck&'\
'vehicle[grossWeight]=40000&'\
'apiKey=YOUR_API_KEY'

It's important to check the response for notices: It's not that unlikely that the car-based route violates some truck restriction, for example:

"notices": [
  {
    "title": "Violated vehicle restriction.",
    "code": "violatedVehicleRestriction",
    "severity": "critical",
    "details": [
      {
        "type": "restriction",
        "cause": "Route violates vehicle restriction",
        "maxWeight": {
          "value": 24000,
          "type": "current"
        },
        ...
      }
    ]
  }
]

If the route is going through segments that are forbidden to use due to transport mode access restrictions, the routeHandle request will fail completely. For example, evaluating a route for truck that goes through a pedestrian park:

{
  "notices": [
    {
      "title": "Route handle decoding failed due to forbidden segments for the specified transport mode.",
      "code": "violatedTransportModeInRouteHandleDecoding",
      "severity": "critical"
    }
  ],
  "routes": []
}