Distance Matrix
Problem: I need travel times between many origins and many destinations. Not a loop of routing calls.Prerequisites
- A HERE API key with Matrix Routing entitlement
export HERE_API_KEY="..."
Size ceilings depend on mode
The code — async, which is what you want at scale
Response walkthrough
errorCodes is a parallel flat array. 3 means a route was found but it violates a restriction. Read it.
Common mistakes
Looping the Routing API. The reason this page exists. Indexing the flat array as if it were nested. Silently transposed. Constructing thestatusUrl. HERE’s spec explicitly warns that a self-built URL may resolve to a different region and return 404. Use the returned one.
Blocking a request thread on an async job. Submit, persist, return, poll on a worker.
Losing the matrixId on restart. Resubmission is a full recharge.
Architecting against a size ceiling from a comparison table. Read the spec.
Building a truck matrix in car mode. Matrix accepts truck parameters. Wrong times, wrong assignments.
Requesting consumptions when nothing reads them.
Ignoring errorCodes. A cell with 3 returned a route that breaks a constraint.
Production considerations
PersistmatrixId and statusUrl before the first poll. The job runs on HERE’s side whether or not your process remembers it.
Cache on a hash of the input set. Depot locations do not move. If origins, destinations, and departure time are unchanged, the matrix is unchanged.
Write exactly one indexing helper. Unit-test it against a hand-computed 2×3. Never index the array anywhere else. This is the highest-value five lines in a matrix integration.
Handle 429 on submission with backoff. Concurrent job limits exist.
Pass truck parameters for commercial fleets. Same vehicle[...] fields as Truck Route.
Region mode caps at 400 km diameter. Beyond that you are in Flexible or Profile mode, with different ceilings and different trade-offs.
Related
Matrix Routing
Modes, region definitions, and the async lifecycle in full.
Routing vs Matrix
The loop, why engineers write it, and the decision tree.
Fleet Routing
Where the matrix feeds the solver.
Cost Optimization Patterns
Pattern 2: choosing the right primitive.
HERE documentation
- Matrix Routing v8 OpenAPI specification — authoritative on modes, limits, and error codes
- Matrix Routing API v8
Need production HERE API keys or implementation support? Placematic is an official HERE Technologies reseller and implementation partner. Talk to us.