TMaps API examples / 11

Nearest driver with a distance matrix

A new order comes in: which driver can reach the customer first? The TMaps Distance Matrix API returns the real road travel time from every driver to the customer in a single call. Click the map to move the customer.

Click the map or drag the customer marker.

API request
POST https://api.tmaps.tn/routing/matrix?api_key=YOUR_API_KEY

How it works

  1. The page sends POST /routing/matrix with the drivers as origins and the customer as the only destinations entry.
  2. durations[i][j] is the time in seconds from origins[i] to destinations[j], and distances[i][j] the distance in meters.
  3. The driver with the smallest durations[i][0] gets the order.

Good to know

  • Up to 25 origins × 25 destinations (625 pairs) per request. Split larger matrices into batches.
  • The nearest driver as the crow flies is often not the fastest one: one-way streets and road layout change the ranking.
  • Set metrics to ["duration"] if you do not need distances.

Distance Matrix docs · Source on GitHub