Documentation menu

Guides

Calculate driving distance between two points

Step-by-step guide to calculating real road distance and drive time between two coordinates with the Wayline Distance API, in eight languages.

Updated Dec 1, 2026 View Markdown

The Distance API returns the driving distance and estimated drive time between an origin and a destination along the road network — not the straight-line ("as the crow flies") distance.

1. Get coordinates

You need latitude/longitude for both points. If you have addresses, geocode them with your geocoding provider first and cache the result. Remember the order: lat,lng.

2. Call the API

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"

3. Use the result

Response (example)
{
  "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
}

Use distance_meters and duration_seconds for calculations, and distance_text / duration_text for display. Pass units=imperial for miles.

POST with structured coordinates

If you'd rather send JSON, POST /v1/distance accepts objects or arrays:

bash
curl -X POST "https://api.wayline.cloud/v1/distance" \
  -H "Authorization: Bearer $WAYLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin": {"lat": 23.7925, "lng": 90.4078}, "destination": [23.733, 90.4172], "units": "imperial"}'

Straight-line vs road distance

Straight-line (haversine) distance underestimates real travel, often by 20–40% in cities and much more where rivers, highways or one-way systems force detours. Use road distance whenever money or time depends on the result — delivery fees, mileage, ETAs.

Many points?

  • Comparing one origin with many destinations → use the matrix.
  • An ordered list of stops → use batch distance.

Related: Distance endpoint reference · Coordinates & formats