GET /v1/distance
Distance API for real road distance and drive time
Request and response
curl "https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial" \
-H "Authorization: Bearer $WAYLINE_API_KEY"const res = await fetch(
"https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial",
{ headers: { Authorization: `Bearer ${process.env.WAYLINE_API_KEY}` } },
);
if (!res.ok) throw new Error(`Wayline ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);import os, requests
res = requests.get(
"https://api.wayline.cloud/v1/distance",
params={"origin": "37.788,-122.4075", "destination": "37.8044,-122.2712", "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"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("WAYLINE_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(body))
}<?php
$ch = curl_init("https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("WAYLINE_API_KEY")],
CURLOPT_TIMEOUT => 10,
]);
$data = json_decode(curl_exec($ch), true);
print_r($data);require "net/http"
require "json"
uri = URI("https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial")
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
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 {
var req = HttpRequest.newBuilder(URI.create("https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial"))
.header("Authorization", "Bearer " + System.getenv("WAYLINE_API_KEY"))
.GET().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.get(
Uri.parse('https://api.wayline.cloud/v1/distance?origin=37.788,-122.4075&destination=37.8044,-122.2712&units=imperial'),
headers: {'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}'},
);
print(jsonDecode(res.body));
}{
"request_id": "req_01JD8Q4ZK7V3",
"distance_meters": 19870,
"duration_seconds": 1260,
"distance_miles": 12.3,
"distance_text": "12.3 mi",
"duration_text": "21 mins",
"origin": {
"location": [
37.788,
-122.4075
],
"snapped": [
37.7881,
-122.4076
],
"distance_to_road_meters": 4
},
"destination": {
"location": [
37.8044,
-122.2712
],
"snapped": [
37.8045,
-122.2713
],
"distance_to_road_meters": 7
},
"snap_distance_meters": 7,
"region": "us",
"map_version": "20261121-2330",
"units_charged": 1
}What the Distance API gives you
Road network, not straight lines
Distances follow real roads from OpenStreetMap with a car profile, including one-way streets and turn restrictions.
Meters, miles and readable text
Pass units=imperial for distance_miles plus ready-to-display strings like “6.5 mi” and “23 mins”.
Snapping you can see
Each endpoint returns the snapped road location and how far it moved, so you can flag bad GPS fixes.
One unit per request
A successful call costs one unit. Errors (4xx/5xx) are never billed, and cache hits cost the same as fresh results.
How the Distance API works
Wayline finds the region that contains both points, snaps each coordinate to the nearest drivable road and runs a shortest-time route on the Wayline routing engine. The response includes distance_meters, duration_seconds, the snapped locations, the region and the exact map version used, so results are reproducible and auditable.
Accepted coordinate formats
Coordinates use Google’s lat,lng order. GET requests take origin=23.7925,90.4078 strings; the POST variant also accepts {"lat":…, "lng":…} objects or [lat, lng] arrays.
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.
Does the drive time include live traffic?
Not yet. Drive times are free-flow estimates based on road types and speed data in OpenStreetMap. Traffic-aware ETAs are on the roadmap; we will announce them in the changelog.
How fast is a distance request?
Most of the time is spent in the routing engine for your region, and identical requests are served from cache. We will publish measured latency with our benchmark methodology rather than quoting unverified numbers.
Start building in minutes
Create an account, grab a test key and make your first request in under five minutes.