Skip to content
GuidesPlaygroundDashboard

Calculate a distance matrix between points

client.routing.matrix(RoutingMatrixParams { destinations, origins, mode } body, RequestOptionsoptions?): MatrixResult { distances, durations }
POST/api/v1/matrix

Calculate a distance matrix between points

ParametersExpand Collapse
body: RoutingMatrixParams { destinations, origins, mode }
destinations: GeoJsonGeometry { coordinates, type }

Destination points (GeoJSON MultiPoint geometry)

coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
origins: GeoJsonGeometry { coordinates, type }

Origin points (GeoJSON MultiPoint geometry)

coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
mode?: "auto" | "foot" | "bicycle"

Travel mode

One of the following:
"auto"
"foot"
"bicycle"
ReturnsExpand Collapse
MatrixResult { distances, durations }
distances: Array<Array<number | null>>

Distance matrix (meters), origins x destinations

durations: Array<Array<number | null>>

Duration matrix (seconds), origins x destinations

Calculate a distance matrix between points

import Plaza from '@plazafyi/sdk';

const client = new Plaza({
  apiKey: process.env['PLAZA_API_KEY'], // This is the default and can be omitted
});

const matrixResult = await client.routing.matrix({
  destinations: { coordinates: [0], type: 'Point' },
  origins: { coordinates: [0], type: 'Point' },
});

console.log(matrixResult.distances);
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}
Returns Examples
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}