Skip to main content

Overview

Calculate a distance and/or travel-time matrix between multiple locations. Use this tool when the user needs to:
  • find the nearest driver, vehicle, store, or facility
  • compare several destinations
  • compare multiple origin-destination pairs
  • build a distance or travel-time matrix
Do not use it for a single route between two locations. Use route instead.

Input

Each coordinate has a stable zero-based index based on its position in the coordinates array. For example:
Matrix rows correspond to sources. Matrix columns correspond to destinations. A matrix value at [row][column] represents the route from that source to that destination. For example:
means the travel time from coordinate 0 to coordinate 2. The response includes sources and destinations with the original coordinate indices so the matrix can be mapped back to the user’s locations.

Sources and destinations

Optional sources and destinations restrict the matrix to subsets of the coordinate indices. For example:
This calculates routes from coordinate 0 to coordinates 1 and 2.

Annotations

Use:
for travel times. Use:
for distances. Use:
for both. If omitted, both are returned.
  • duration — travel time in seconds
  • distance — distance in meters

Motorcycle routing

Set:
when the user explicitly asks for motorcycle or motorbike routing. Otherwise, omit profile.

Nearest-driver example

For a question such as:
Which driver is closest to the customer?
Keep the locations in a fixed order:
Then:
  1. Use [0] as the source.
  2. Use the driver indices as destinations.
  3. Read the corresponding values from the first matrix row.
  4. Ignore null values.
  5. Choose the smallest distance or duration, depending on the user’s request.
For example:

Output

durations are in seconds. distances are in meters. A matrix value of null means that the origin-destination pair is unreachable. Never interpret null as zero. If the user provides place names or addresses instead of coordinates, call geocode first for every place. Keep the locations in the same order when constructing the matrix request.

Example

Prompt for an MCP-capable agent, e.g. Claude or Codex