Geodesic segment length calculator
Measure the shortest path over the Earth's surface between two coordinates: from 40.7128, -74.006 to 51.5074, -0.1278 it is 5570.229874 km, shown in metres and miles as well. The Earth is treated as a sphere of mean radius. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Lat1
- 40.7128
- Lon1
- -74.006
- Lat2
- 51.5074
- Lon2
- -0.1278
- Meters
- 5,570,229.873657
- Kilometers
- 5,570.229874
- Miles
- 3,461.180378
The geodesic segment length calculator measures the shortest great-circle path between two positions supplied as decimal latitude and longitude coordinates. It returns the same distance in meters, kilometers, and miles, making the result ready for maps, reports, validation rules, or application interfaces without extra unit conversion. The calculation is deterministic, uses a fixed mean Earth radius, and does not contact a mapping service.
Enter the two ends of the segment
A segment begins at the coordinate described by lat1 and lon1 and ends at the coordinate described by lat2 and lon2. Supply every value as a decimal number, with latitude between negative ninety and positive ninety degrees and longitude between negative one hundred eighty and positive one hundred eighty degrees. Southern latitudes and western longitudes use negative signs.
Keep all four values in the same conventional geographic coordinate system; do not submit projected map coordinates, degree-minute-second text, or distances. More decimal places describe a more precise location, although the result remains a spherical approximation of Earth. Validation rejects missing values, text, non-finite numbers, and coordinates outside their geographic ranges instead of silently guessing what the caller intended.
This strict behavior is useful in automated pipelines because malformed records fail clearly before an incorrect distance reaches a customer, route table, or spatial report.
Understand the great-circle calculation
Multiplying that angle by the fixed mean Earth radius of 6,371,008.8 meters gives the great-circle segment length. A great circle represents the shortest path over an ideal spherical Earth, not the length of a straight chord through the planet and not a road, walking, or rail route. Because the real Earth is an oblate ellipsoid and local terrain adds elevation, the number can differ from a survey-grade ellipsoidal geodesic or a distance measured along the ground.
Use an ellipsoidal or terrain-aware method when those distinctions are material to the decision being made.
Use the returned units safely
Meters are convenient for short separations and threshold comparisons, kilometers work well for regional or international summaries, and miles support interfaces intended for audiences that use statute miles. Store one canonical field when later calculations must avoid accumulating rounding differences, and treat the other fields as ready-to-display conversions of that same segment. In a batch workflow, call the capability once per segment and associate each response with the corresponding record identifier in your own system.
The calculation has no network access, live map data, traffic, borders, or route restrictions; its repeatability comes from using only the submitted coordinates and fixed constants. Before enforcing a business cutoff, choose a tolerance appropriate to coordinate accuracy and the spherical model instead of comparing rounded values as though they were exact land-survey observations.
What you can do with it
Check a proximity threshold
Measure whether two stored positions are approximately close enough for a location-based application rule.
Label a map segment
Calculate a stable distance for a line drawn between two coordinate markers and display the preferred unit.
Validate geographic records
Flag coordinate pairs whose separation is unexpectedly large or small before importing them into another system.
FAQ
Is this a road or walking distance?
No. It is the shortest great-circle distance over a spherical Earth model and does not follow a transport network.
Which kind of miles are returned?
The miles field uses international statute miles, with exactly 1,609.344 meters per mile.
Why can this differ from a survey-grade result?
It uses a fixed mean-radius spherical model rather than an ellipsoid, elevation model, or measured ground path.
Does the order of the two points matter?
No. Swapping the first and second pair of coordinates gives exactly the same length, so you can enter the two ends in whichever order your data uses.
What happens if both ends are the same point?
The length is zero in every unit. Identical coordinates are valid input, so a record that starts and ends at the same place gives zero instead of being refused.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/geo/segment-length \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"lat1":40.7128,"lon1":-74.006,"lat2":51.5074,"lon2":-0.1278}'const res = await fetch("https://api.kit.forhosting.com/geo/segment-length", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"lat1": 40.7128,
"lon1": -74.006,
"lat2": 51.5074,
"lon2": -0.1278
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/geo/segment-length",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"lat1": 40.7128,
"lon1": -74.006,
"lat2": 51.5074,
"lon2": -0.1278
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/geo/segment-length", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"lat1":40.7128,"lon1":-74.006,"lat2":51.5074,"lon2":-0.1278}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"lat1":40.7128,"lon1":-74.006,"lat2":51.5074,"lon2":-0.1278}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/geo/segment-length", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"lat1": 40.7128,
"lon1": -74.006,
"lat2": 51.5074,
"lon2": -0.1278
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "geo.segment_length",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Enter one pair of coordinates for the starting endpoint and another pair for the ending endpoint to obtain a clear, repeatable measurement.
Define the segment with two valid endpoints
The endpoint order does not change the length, so exchanging the first and second pair produces the same answer. Identical endpoint pairs correctly produce zero in every returned unit.
Understand the great-circle calculation
The calculator converts each coordinate from degrees to radians and applies the haversine relationship to find the central angle between the endpoints.
Use the returned units safely
The response contains meters, kilometers, and miles as numeric fields, so a consumer can select the display unit without repeating the geographic calculation. The endpoint coordinates are not echoed, so retain the original input beside the result if an audit trail must show exactly which locations were measured. API execution costs $0.002 per item.
Technical questions
What does one API calculation cost?
Each segment calculation costs $0.002.
What happens when both endpoints are identical?
The calculator returns zero meters, zero kilometers, and zero miles.