ForHosting KIT · Travel & geography

Haversine great-circle distance

Measure the great-circle distance between two coordinates with the formula shown next to the result: New York to London comes out at 5570.229874 km, with metres, miles and a central angle of 50.094212°. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Lat1
40.7128
Lon1
-74.006
Lat2
51.5074
Lon2
-0.1278
You get
Distance m
5,570,229.874
Distance km
5,570.229874
Distance mi
3,461.180378
Central angle deg
50.094212

Great-circle distance is the shortest path over the surface of a sphere between two geographic coordinates. Pilots, logistics planners, GIS developers, and data scientists all need a reproducible number for “how far is A from B” without pulling a full mapping stack. This haversine great-circle distance calculator takes two latitude/longitude pairs, applies the numerically stable haversine formula on a mean spherical Earth radius of 6 371 008.8 metres, and returns distance in metres, kilometres, and statute miles plus the central angle in degrees. Use it when a spherical model is enough and you want a transparent formula string you can show next to the result.

What the haversine great-circle formula computes

On a perfect sphere of radius R, the shortest surface path between two points is an arc of a great circle whose central angle Δσ satisfies a simple trigonometric identity in latitude and longitude. The classical spherical law of cosines works in exact arithmetic but loses precision for short separations when cosines of nearly equal angles subtract in floating point.

The haversine form rewrites the same geometry using half-angle sines: define a as sin²(Δφ/2) plus cos φ1 cos φ2 sin²(Δλ/2), clamp a into the unit interval so rounding noise cannot push it slightly outside [0, 1], then set the central angle c equal to two times atan2 of the square root of a over the square root of one minus a. Distance is R times c. That atan2 pair stays well-conditioned for both kilometre-scale city hops and near-antipodal pairs.

This capability fixes R at the IUGG mean Earth radius 6 371 008.8 metres so every caller shares one documented sphere instead of mixing 6371 km, 6378 km, and authalic variants in the same spreadsheet. The model ignores topography, ellipsoidal flattening, and altitude; if you need WGS-84 geodesic accuracy at the centimetre level, use an ellipsoidal inverse such as Vincenty instead. For routing, logistics ETAs, educational demos, and SEO landings that search for haversine great circle distance, the spherical answer is usually the right product surface.

Logistics and ETA rough estimates

Compute as-the-crow-flies kilometres between depot and delivery coordinates before applying road factors or carrier matrices.

Store locator and proximity filters

Rank candidate branches by great-circle distance from a user lat/lon without embedding a full GIS stack in the client.

How do I compute haversine great-circle distance between two points?

Send lat1, lon1, lat2, and lon2 in decimal degrees.

What Earth radius does this calculator use?

A mean spherical radius of 6 371 008.8 metres (IUGG mean Earth).

Is this the same as driving or flight distance?

No. It is the shortest surface arc on a sphere (great-circle). Roads, airways, and terrain make real travel longer; use routing APIs for those.

What if my latitude or longitude is out of range?

Latitudes must lie in [−90, 90] and longitudes in [−180, 180]. Invalid input is not billed.

What is the central angle shown with the distance?

It is the angle between the two points seen from the center of the Earth, 50.094212° for New York to London. Multiplying that angle, in radians, by the fixed radius of 6,371,008.8 metres gives the distance along the surface.

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.

POSThttps://api.kit.forhosting.com/geo/haversine-distance

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.

curl -X POST https://api.kit.forhosting.com/geo/haversine-distance \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"lat1":40.7128,"lon1":-74.006,"lat2":51.5074,"lon2":-0.1278}'
{
  "lat1": 40.7128,
  "lon1": -74.006,
  "lat2": 51.5074,
  "lon2": -0.1278
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "geo.haversine_distance",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Invalid latitudes or longitudes fail with invalid_input and are not billed.

What the haversine great-circle formula computes

Outputs report distance_m, distance_km, and distance_mi (international statute mile of 1609.344 m), central_angle_deg for map math, earth_radius_m for audit trails, and a compact formula string.

Input contract, response fields, and validation rules

Example: New York at about 40.7128, −74.0060 and London at about 51.5074, −0.1278 yield roughly five thousand five hundred seventy kilometres of great-circle arc—the figure you compare against airline route maps that quote great-circle rather than road distance. Identical points produce zero distance and zero central angle. Crossing the antimeridian is handled by the spherical trig itself; you do not need to normalise longitudes beyond the ±180 range check. POST a JSON body with four required finite numbers: lat1 and lat2 in decimal degrees between −90 and 90, and lon1 and lon2 between −180 and 180. Longitude also accepts the aliases lng1 and lng2 so clients written against common GIS field names do not need a rename step. Missing fields, empty strings, non-finite values, and out-of-range coordinates fail with invalid_input naming the field; those failures do not consume prepaid balance. Pair the response with your own unit labels in the UI; the API does not convert to nautical miles or feet in this contract.

When to call this API in products and pipelines

Fleet dashboards, travel estimators, and store-locator prototypes need a cheap, documented great-circle distance without embedding a geodesy library in every language runtime. Keep requests small, pin rounded distances in integration tests, and document that results are spherical—not driving distance, not flight level adjusted, and not ellipsoidal. Classroom and GIS training materials use the returned formula string and fixed radius so students can reproduce the number by hand with a scientific calculator and verify the API. Mobile and edge apps prefer a tiny deterministic endpoint over pulling Mapbox Matrix or Google Distance Matrix when only as-the-crow-flies distance matters and road network topology does not. If your product later needs higher fidelity, keep this endpoint for the fast path and escalate long-haul precision routes to an ellipsoidal geodesic capability without changing the four-field input shape. Failed validation remains free; successful calls stay at $0.002 so pricing never surprises a bulk enrichment job that only needed spherical metres.

Education and GIS notebooks

Show students the stable haversine formula with a fixed mean Earth radius and verify homework against the API golden rounding.

What does the haversine great-circle distance calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; validation failures do not consume balance.

Read the full KIT documentation →