Skip to content
GuidesPlaygroundDashboard

Calculate a distance matrix between points

routing.matrix(**kwargs) -> MatrixResult { distances, durations }
POST/api/v1/matrix

Calculate a distance matrix between points

ParametersExpand Collapse
destinations: GeoJsonGeometry { coordinates, type }

Destination points (GeoJSON MultiPoint geometry)

coordinates: Array[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array[Float]
Array[Array[Float]]
Array[Array[Array[Float]]]
Array[Array[Array[Array[Float]]]]
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[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array[Float]
Array[Array[Float]]
Array[Array[Array[Float]]]
Array[Array[Array[Array[Float]]]]
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
class MatrixResult { distances, durations }
distances: Array[Array[Float]]

Distance matrix (meters), origins x destinations

durations: Array[Array[Float]]

Duration matrix (seconds), origins x destinations

Calculate a distance matrix between points

require "plaza"

plaza = Plaza::Client.new(
  api_key: "My API Key",
  environment: "local" # defaults to "production"
)

matrix_result = plaza.routing.matrix(
  destinations: {coordinates: [0], type: :Point},
  origins: {coordinates: [0], type: :Point}
)

puts(matrix_result)
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}
Returns Examples
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}