POST /v1/distance/batch
Batch Distance API for consecutive stops and mileage
Request and response
curl -X POST "https://api.wayline.cloud/v1/distance/batch" \
-H "Authorization: Bearer $WAYLINE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"points":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}'const res = await fetch("https://api.wayline.cloud/v1/distance/batch", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WAYLINE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"points": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
},
{
"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/distance/batch",
json={
"points": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
},
{
"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 := `{"points":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852},{"lat":37.8716,"lng":-122.2727},{"lat":37.9358,"lng":-122.3478}],"units":"imperial"}`
req, _ := http.NewRequest("POST", "https://api.wayline.cloud/v1/distance/batch", 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/distance/batch");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("WAYLINE_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => '{"points":[{"lat":37.788,"lng":-122.4075},{"lat":37.8313,"lng":-122.2852},{"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/distance/batch")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
req.body = {points: [{lat: 37.788, lng: -122.4075}, {lat: 37.8313, lng: -122.2852}, {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 = """
{
"points": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
},
{
"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/distance/batch"))
.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/distance/batch'),
headers: {
'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}',
'Content-Type': 'application/json',
},
body: jsonEncode({
"points": [
{
"lat": 37.788,
"lng": -122.4075
},
{
"lat": 37.8313,
"lng": -122.2852
},
{
"lat": 37.8716,
"lng": -122.2727
},
{
"lat": 37.9358,
"lng": -122.3478
}
],
"units": "imperial"
}),
);
print(jsonDecode(res.body));
}{
"request_id": "req_01JD8Q6C9T4P",
"legs": [
{
"from_index": 0,
"to_index": 1,
"distance_meters": 6120,
"duration_seconds": 840,
"status": "OK"
},
{
"from_index": 1,
"to_index": 2,
"distance_meters": 3010,
"duration_seconds": 420,
"status": "OK"
},
{
"from_index": 2,
"to_index": 3,
"distance_meters": 12840,
"duration_seconds": 1080,
"status": "OK"
}
],
"total_distance_meters": 21970,
"total_duration_seconds": 2340,
"region": "us",
"map_version": "20261121-2330",
"units_charged": 3
}What the Batch Distance API gives you
N points, N − 1 legs
Each consecutive pair is routed independently, so the result matches how the trip was driven.
Totals included
total_distance_meters and total_duration_seconds (plus miles with units=imperial) for reimbursement reports.
Per-leg status
A single unroutable leg returns NO_ROUTE without failing the batch.
Billed per pair
Units charged = number of pairs (points − 1).
Built for mileage reimbursement
Group check-ins by day in the employee’s time zone, send each day as one batch and store the per-leg results with the map version for audit trails. Our guide shows the full pattern.
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.
Why not use the matrix endpoint for consecutive stops?
A matrix computes every origin-destination combination, so 10 stops would cost 100 elements. The batch endpoint computes only the 9 consecutive legs you need.
Start building in minutes
Create an account, grab a test key and make your first request in under five minutes.