📐

Distance Calculator

Calculate the distance between two or more geographic coordinates

POST 1 credit /v1/geo/distance
curl -X POST "https://geo.toolkitapi.io/v1/geo/distance" \
  -H "Content-Type: application/json" \
  -d '{
    "points": [
      {"lat": 40.7128, "lon": -74.006},
      {"lat": 51.5074, "lon": -0.1278}
    ],
    "unit": "km",
    "method": "haversine"
  }'
import httpx

resp = httpx.post(
    "https://geo.toolkitapi.io/v1/geo/distance",
    json={
    "points": [
      {"lat": 40.7128, "lon": -74.006},
      {"lat": 51.5074, "lon": -0.1278}
    ],
    "unit": "km",
    "method": "haversine"
  },
)
print(resp.json())
const resp = await fetch("https://geo.toolkitapi.io/v1/geo/distance", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "points": [
      {"lat": 40.7128, "lon": -74.006},
      {"lat": 51.5074, "lon": -0.1278}
    ],
    "unit": "km",
    "method": "haversine"
  }),
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "total_distance": 5570.222,
  "unit": "km",
  "method": "haversine",
  "legs": [
    {
      "from_point": {"lat": 40.7128, "lon": -74.006},
      "to_point": {"lat": 51.5074, "lon": -0.1278},
      "distance": 5570.222
    }
  ]
}

Try It Live

Live Demo

Description

Calculate the distance between two or more geographic coordinates

How to Use

1

1. Provide an array of at least two coordinate points in the `points` field, each with `lat` and `lon`.

2

2. Optionally set `unit` to `km`, `mi`, `m`, or `nm` (default: `km`) and `method` to `haversine` or `vincenty`.

3

3. Send a POST request and inspect `total_distance` for the cumulative distance across all legs.

4

4. Use the `legs` array for individual segment distances when routing through multiple waypoints.

About This Tool

Use the Distance Calculator to compute the great-circle distance between two or more geographic coordinates using either the Haversine or Vincenty (spherical) formula. When more than two points are provided, the endpoint calculates each leg individually and returns the total distance.

This supports multiple units including kilometres, miles, metres, and nautical miles, making it suitable for logistics, travel planning, and geospatial analysis.

Why Use This Tool

Frequently Asked Questions

What is the difference between Haversine and Vincenty?
Both calculate great-circle distances on a sphere. Vincenty's spherical formula is more numerically stable for antipodal points (locations on opposite sides of the Earth). For most practical purposes they return nearly identical results.
Can I calculate multi-stop routes?
Yes. Provide three or more points and the endpoint returns individual leg distances plus the total. Points are connected in order.
What is the maximum number of points?
There is no hard limit, but very large arrays may increase response time. For typical use cases (under 100 waypoints), performance is excellent.

Start using Distance Calculator now

Get your free API key and make your first request in under a minute.