- Home
- Docs
- API reference
- Many-to-many travel time and road distance matrix
API reference
Many-to-many travel time and road distance matrix
Calculates road distances and durations between every origin and destination. Units charged equals `origins × destinations`.
Endpoint
POST
Bearer Authhttps://api.wayline.cloud/v1/matrixRequires an API key (authentication). Product overview: Distance Matrix API. Billing: see units & pricing.
Request body
JSON object (MatrixRequest). Points accept "lat,lng" strings, {lat, lng} objects or [lat, lng] arrays.
| Field | Type | Description |
|---|---|---|
origins | Point[] | |
destinations | Point[] | |
points | Point[] | Alternative for symmetric N x N matrices. |
metrics | string | One of: distance, duration, bothDefault: both |
profile | string | One of: car, driving, motorcycle, bike, motorbike, two_wheeler, bicycle, cyclingDefault: car |
units | string | One of: metric, imperialDefault: metric |
Example
curl -X POST "https://api.wayline.cloud/v1/matrix" \
-H "Authorization: Bearer $WAYLINE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"origins":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852}],"destinations":[{"lat":37.8044,"lng":-122.2712},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}'const res = await fetch("https://api.wayline.cloud/v1/matrix", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WAYLINE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"origins": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
}
],
"destinations": [
{
"lat": 37.8044,
"lng": -122.2712
},
{
"lat": 37.8716,
"lng": -122.2727
},
{
"lat": 37.9358,
"lng": -122.3478
}
],
"units": "imperial"
}),
});
if (!res.ok) throw new Error(`Wayline ${res.status}: ${await res.text()}`);
console.log(await res.json());import os, requests
res = requests.post(
"https://api.wayline.cloud/v1/matrix",
json={
"origins": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
}
],
"destinations": [
{
"lat": 37.8044,
"lng": -122.2712
},
{
"lat": 37.8716,
"lng": -122.2727
},
{
"lat": 37.9358,
"lng": -122.3478
}
],
"units": "imperial"
},
headers={"Authorization": f"Bearer {os.environ['WAYLINE_API_KEY']}"},
timeout=10,
)
res.raise_for_status()
print(res.json())package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := `{"origins":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852}],"destinations":[{"lat":37.8044,"lng":-122.2712},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}`
req, _ := http.NewRequest("POST", "https://api.wayline.cloud/v1/matrix", strings.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("WAYLINE_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(out))
}<?php
$ch = curl_init("https://api.wayline.cloud/v1/matrix");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("WAYLINE_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => '{"origins":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852}],"destinations":[{"lat":37.8044,"lng":-122.2712},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}',
CURLOPT_TIMEOUT => 10,
]);
print_r(json_decode(curl_exec($ch), true));require "net/http"
require "json"
uri = URI("https://api.wayline.cloud/v1/matrix")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
req.body = {origins: [{lat: 37.788, lng: -122.4075}, {lat: 37.8313, lng: -122.2852}], destinations: [{lat: 37.8044, lng: -122.2712}, {lat: 37.8716, lng: -122.2727}, {lat: 37.9358, lng: -122.3478}], units: "imperial"}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(req) }
puts JSON.parse(res.body)import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
String body = """
{
"origins": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
}
],
"destinations": [
{
"lat": 37.8044,
"lng": -122.2712
},
{
"lat": 37.8716,
"lng": -122.2727
},
{
"lat": 37.9358,
"lng": -122.3478
}
],
"units": "imperial"
}
""";
var req = HttpRequest.newBuilder(URI.create("https://api.wayline.cloud/v1/matrix"))
.header("Authorization", "Bearer " + System.getenv("WAYLINE_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)).build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.statusCode() + " " + res.body());
}
}import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.post(
Uri.parse('https://api.wayline.cloud/v1/matrix'),
headers: {
'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}',
'Content-Type': 'application/json',
},
body: jsonEncode({
"origins": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
}
],
"destinations": [
{
"lat": 37.8044,
"lng": -122.2712
},
{
"lat": 37.8716,
"lng": -122.2727
},
{
"lat": 37.9358,
"lng": -122.3478
}
],
"units": "imperial"
}),
);
print(jsonDecode(res.body));
}{
"request_id": "req_01JD8Q7H3W8R",
"rows": [
{
"elements": [
{
"distance_meters": 19870,
"duration_seconds": 1260,
"status": "OK"
},
{
"distance_meters": 6120,
"duration_seconds": 840,
"status": "OK"
},
{
"distance_meters": 14210,
"duration_seconds": 1290,
"status": "OK"
}
]
},
{
"elements": [
{
"distance_meters": 11880,
"duration_seconds": 1500,
"status": "OK"
},
{
"distance_meters": 3010,
"duration_seconds": 420,
"status": "OK"
},
{
"distance_meters": 12840,
"duration_seconds": 1080,
"status": "OK"
}
]
}
],
"origins": [
"…"
],
"destinations": [
"…"
],
"region": "us",
"map_version": "20261121-2330",
"units_charged": 6
}Response
200 — Successful matrix response.
| Field | Type | Description |
|---|---|---|
rowsrequired | MatrixRow[] | |
rows[].elementsrequired | MatrixElement[] | |
rows[].elements[].distance_meters | integer | |
rows[].elements[].duration_seconds | integer | |
rows[].elements[].distance_miles | number | |
rows[].elements[].distance_text | string | |
rows[].elements[].duration_text | string | |
rows[].elements[].statusrequired | string | One of: OK, NO_ROUTE |
profilerequired | string | Canonical routing profile used (car, motorcycle or bicycle). |
regionrequired | string | |
map_versionrequired | string | |
warnings | string[] | |
units_chargedrequired | integer |
Response headers
X-Request-Id— Unique identifier for tracking and debugging this request.X-RateLimit-Limit— Maximum permitted requests in current window.X-RateLimit-Remaining— Remaining request quota in current window.X-RateLimit-Reset— Seconds until the rate limit window resets.X-Units-Charged— Billable request units consumed by this request.X-Cache— Cache lookup status (`HIT` or `MISS`).X-Region— Region code serving this routing request (e.g. `bd`).
Errors
| Status | When |
|---|---|
400 | Bad request (invalid coordinates, out of coverage, too many elements, etc.). |
401 | Missing or invalid API key, or expired key. |
402 | Free quota exhausted, no payment method, account suspended, or the monthly spend limit you set was reached. Never billed. Raise or remove the limit in the dashboard (Billing) and retry; nothing else changes. |
403 | Account disabled, key IP restriction failed, origin not allowed, or scope not permitted. |
429 | Rate limit exceeded or test key daily quota reached. |
500 | Internal server error. |
503 | Upstream routing service temporarily unavailable. |
Error bodies contain a code such as OUT_OF_COVERAGE — see the error reference.
Try it
Interactive API Console
Sends a real request from your browser using a test key (free, never billed). The key stays in this browser tab only.
No key yet? Create a free test key.