Skip to content
GuidesBlogPlaygroundDashboard

Calculate a distance matrix between points

$client->routing->matrix(list<Destination> destinations, list<Origin> origins, ?string annotations, ?float fallbackSpeed, ?Mode mode): MatrixResult
POST/api/v1/matrix

Calculate a distance matrix between points

ParametersExpand Collapse
destinations: list<Destination>

Array of destination coordinates (max 50)

origins: list<Origin>

Array of origin coordinates (max 50)

annotations?:optional string

Comma-separated list of annotations to include: duration (always included), distance. Example: duration,distance.

fallbackSpeed?:optional float

Fallback speed in km/h for pairs where no route exists. When set, unreachable pairs get estimated values instead of null.

mode?:optional Mode

Travel mode (default: auto)

ReturnsExpand Collapse
array<string,mixed>

Distance matrix result. The exact response shape depends on the routing backend. Contains duration (and optionally distance) data for all origin-destination pairs. Null values indicate unreachable pairs.

Calculate a distance matrix between points

<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

$client = new Client(apiKey: 'My API Key', environment: 'local');

$matrixResult = $client->routing->matrix(
  destinations: [['lat' => 48.8584, 'lng' => 2.2945]],
  origins: [
    ['lat' => 48.8566, 'lng' => 2.3522], ['lat' => 48.8606, 'lng' => 2.3376]
  ],
  annotations: 'annotations',
  fallbackSpeed: 1,
  mode: 'auto',
);

var_dump($matrixResult);
{
  "foo": "bar"
}
Returns Examples
{
  "foo": "bar"
}