POST /v1/matrix
Distance Matrix API for many-to-many drive times
Request and response
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
}What the Distance Matrix API gives you
Origins × destinations
Rectangular matrices with origins and destinations, or a symmetric N × N matrix with points.
Choose your metrics
Ask for distance, duration or both to keep payloads small.
Per-element status
Each cell has its own status (OK or NO_ROUTE), so one unreachable pair never fails the whole request.
Billed per element
Units charged = origins × destinations, shown in the X-Units-Charged header on every response.
When to use a distance matrix
Use the matrix when you need to compare many candidates at once: which driver is closest by drive time, which customers fall inside a 30-minute delivery radius, or the input cost matrix for a route optimizer.
Limits
The maximum number of elements per request depends on your rate-limit plan and is shown on this page and in your dashboard. Split larger jobs into tiles; each tile is billed by its element count only.
Frequently asked questions
Is the distance a straight line or a real road distance?
Always real road distance. Every result is computed along the OpenStreetMap road network with a driving profile, never as a straight-line (haversine) estimate.
Which areas do you cover?
Coverage is region-based. The Coverage page lists every enabled region with its map data date. Points outside an enabled region return an OUT_OF_COVERAGE error and are never billed.
How is a matrix request billed?
One unit per element: a 10 × 20 matrix is 200 units. Only successful (2xx) responses are billed. Elements with status NO_ROUTE are still part of the requested matrix.
Can I send addresses instead of coordinates?
The matrix takes coordinates. Where geocoding is available (Bangladesh today), turn addresses into lat,lng with the Geocoding API first, then send the coordinates; elsewhere, geocode with the provider of your choice.
Start building in minutes
Create an account, grab a test key and make your first request in under five minutes.