Skip to main content

Distance Matrix

Problem: I need travel times between many origins and many destinations. Not a loop of routing calls.
If you are calling the Routing API in a loop to build a table of travel times, this page will pay for itself. A 20×500 problem is 10,000 routing calls, or one matrix request.

Prerequisites

  • A HERE API key with Matrix Routing entitlement
  • export HERE_API_KEY="..."

Size ceilings depend on mode

There is no single “HERE matrix size limit.” Verified against the Matrix Routing v8 OpenAPI specification, v8.47.0:A truck-constrained matrix with live traffic runs in Flexible mode and caps at 15 × 100. Read the spec before architecting.

The code — async, which is what you want at scale

Response walkthrough

travelTimes is flat and row-major. [73, 1231, 983, 400] for a 2×2 means: dest0 dest1 origin0 73 1231 origin1 983 400 Index as travelTimes[origin * numDestinations + destination].Transpose it and every value is plausible, every assignment is wrong, and nothing throws. This is why matrix bugs survive code review.
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 the statusUrl. 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

Persist matrixId 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.

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


Need production HERE API keys or implementation support? Placematic is an official HERE Technologies reseller and implementation partner. Talk to us.