Skip to main content

Calculate a Truck Route

Problem: I need a route a 53-foot trailer can physically and legally drive.
transportMode=truck selects the truck routing engine. It does not tell HERE how tall your vehicle is.Omit the dimensions and you get a route. It returns 200. It contains a polyline. It may route a 4.1-metre trailer under a 3.4-metre bridge, and HERE will not warn you, because you did not tell it there was a trailer.

Prerequisites

  • A HERE API key with Routing entitlement
  • Confirm truck routing entitlement specifically — free-tier product coverage varies and should not be assumed
  • export HERE_API_KEY="..."

The code

vehicle supersedes truck. The truck object is marked deprecated in the current v8 specification. weightLimit is deprecated in favour of grossWeight. If you are reading a 2021 tutorial, you are reading deprecated parameters.

Units

Units are not validated for plausibility. Pass 4.1 and HERE routes a four-centimetre vehicle under every bridge in North America. The response is 200.The validation in the Python example above exists for exactly this reason.

Verify the constraints are actually applied

Do not ship truck routing without this test. It is the reason bridge strikes make the news.
Route a 410 cm vehicle through these. Any path returned is a failure.
Wire these into CI, not a manual QA checklist. A refactor that drops vehicle[height] from the params dict is invisible in code review and obvious in a failing test.The car-mode control is not optional. Without it, a test that fails because your coordinates are wrong looks identical to a test that passes because the constraint worked.

Common mistakes

Setting transportMode=truck and stopping there. The engine is selected. The vehicle is not described. Passing metres instead of centimetres. Counting only the tractor’s axles. axleCount includes trailers. Using deprecated truck[...] or weightLimit. Hardcoding dimensions at the call site. They belong on the vehicle record. Treating NoRouteError as a failure to retry with relaxed constraints. That produces an illegal route. Falling back to car routing. Worse than failing. Constraints on the server, absent on the device. The driver deviates, the phone reroutes, and the constraint set never left your backend. Push the profile to the device. Assuming category=lightTruck waives dimension limits. It waives certain legal restrictions. Bridges do not care about your category.

Production considerations

Vehicle profiles are model data. Store them once. Validate at write time — a vehicle record with a null height should fail before it reaches a routing call. Truck routing is slower than car routing. More constraints, larger search space. Size your timeouts. Confirm entitlement before scoping a pilot. Truck routing inclusion in the free tier should be verified against your specific account. For many-to-many truck travel times, Matrix Routing accepts truck parameters. Do not loop. See Distance Matrix. For hazmat, add shippedHazardousGoods (an array of cargo types) and tunnelCategory (B|C|D|E). These are different parameters governing different things. See Hazmat Routing.

Truck Routing

The full constraint set and why omitting one is silent.

Fleet Routing

Where the profile lives, and how it reaches the device.

Hazmat Routing

Cargo types, tunnel categories, and refusing to route.

Routing System Architecture

Constraints belong on records, never at call sites.

HERE documentation

Placematic


Need production HERE API keys or implementation support? Placematic is an official HERE Technologies reseller and implementation partner. We have deployed HERE truck routing into production ELD systems. Talk to us.