Distance Matrix
Calculate distances between multiple points
POST
/routing/matrixCalculate distances and durations between multiple origin and destination points. Returns a matrix where each cell contains the travel metrics from a source to a destination.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
sources | Coordinates[] | Yes | Origin points |
destinations | Coordinates[] | Yes | Destination points |
departure | ISO8601 | No | Departure time for traffic calculation |
Coordinates
| Field | Type | Required | Description |
|---|---|---|---|
lat | number | Yes | Latitude |
lng | number | Yes | Longitude |
Example Response
Response Fields
| Field | Type | Description |
|---|---|---|
durations | number[][] | Duration matrix in seconds |
distances | number[][] | Distance matrix in meters |
Matrix Structure
The response is a 2D array where:
durations[i][j]is the duration fromsources[i]todestinations[j]distances[i][j]is the distance fromsources[i]todestinations[j]
Example with Multiple Sources
Request:
Response:
Use Cases
- Driver Assignment: Find the closest driver to a pickup location
- Route Planning: Pre-compute distances for optimization algorithms
- Service Area Analysis: Determine reachability within time thresholds
- ETA Estimation: Calculate travel times for multiple destinations
Performance
The matrix calculation scales with sources * destinations. For large matrices, consider:
- Batching requests for very large point sets
- Using departure time for accurate traffic-based estimates
- Caching results for static location pairs