ForHosting KIT · Travel & geography

Latitude longitude distance

Turn two latitude and longitude pins into a single figure in kilometres: 40.7128, -74.006 and 51.5074, -0.1278 lie 5570.22218 km apart along the great circle, a number you can store, compare or test against. 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
Km
5,570.22218
Earth radius km
6,371

Latitude and longitude are the coordinates almost every GPS chip, GIS export, and mobile check-in already stores, but converting two of those pins into a distance in kilometres is where many products silently go wrong. Treating decimal degrees as a flat plane stretches a degree of longitude as if it were constant from the equator to the pole, so the same change in longitude is a very different ground length in Quito than in Oslo. This latitude-longitude distance calculator applies the haversine formula on a sphere of mean radius 6371 kilometres and returns the great-circle arc length in kilometres only. Send four decimal-degree numbers, read one kilometre figure you can pin in tests, and skip map tiles, geocoders, and ellipsoidal solvers when a spherical crow-flies kilometre is the contract you need.

What latitude-longitude distance on a sphere actually measures

The shortest path between two points on Earth is not the straight line you draw on a printed map. Printed and web maps flatten a curved surface, so a ruler length in map millimetres is a projection artefact rather than a ground length. Latitude and longitude distance on a sphere instead measures the central angle between two geographic positions and multiplies that angle by the sphere radius to obtain arc length—the great-circle kilometre people mean when they ask how far apart two GPS pins sit as the crow flies.

Given latitudes φ1 and φ2 and longitudes λ1 and λ2 converted to radians, the haversine of the central angle satisfies hav(c) equals hav(φ2 minus φ1) plus the product of cos φ1, cos φ2, and hav(λ2 minus λ1), where hav of an angle is the square of the sine of half that angle.

The numerically stable evaluation used here is a equals sin squared of half the latitude difference plus cos φ1 times cos φ2 times sin squared of half the longitude difference, then c equals two times atan2 of the square root of a over the square root of one minus a, then kilometres equals R times c with R fixed at 6371 kilometres, the conventional mean Earth radius in GPS tutorials and spherical GIS snippets.

That sphere is not the WGS-84 ellipsoid, so polar flattening is ignored and results can differ by a small fraction of a percent from Vincenty or Karney geodesics; for store radii, analytics buckets, and crow-flies filters that gap is usually acceptable. Identical coordinates produce zero. Antipodal pairs produce a result near πR.

The arithmetic is pure and deterministic: no clock, no random seed, no network, and the same four numbers always yield the same rounded kilometre figure.

Where a distance in kilometres helps

Store locators, delivery-radius gates, and marketplace apps already hold shopper and venue coordinates and only need a crow-flies kilometre before they spend money on road routing. Logistics and warehouse prefilters drop hubs that sit outside a great-circle threshold so expensive drive-time engines run only on the shortlist.

Sports and hiking summaries, fraud signals that compare a billing city to a device GPS pin, and bulk CSV enrichment jobs that add a km column next to every origin-destination pair all fit the same pattern: you already have latitudes and longitudes, and you need a deterministic kilometre you can explain in a support ticket. Call the free in-browser latitude longitude distance calculator for classroom demos and quick checks without installing a GIS stack.

For turn-by-turn paths keep a routing engine; for legal property boundaries use an ellipsoidal solver and a local CRS.

Store-locator and delivery radius in kilometres

Compare a shopper GPS pin to each store coordinate and keep only venues whose great-circle distance in kilometres is inside your delivery or pickup radius.

Logistics hub prefilter before road routing

Drop candidate warehouses outside a crow-flies kilometre threshold so paid drive-time APIs only run on the remaining shortlist.

CSV enrichment of origin–destination pairs

Add a kilometres column to shipment, telemetry, or event exports from stored latitudes and longitudes without a maps billing account.

How do I get the distance in kilometres from two latitudes and longitudes?

Send finite decimal-degree fields lat1, lon1, lat2, and lon2.

What happens if a latitude exceeds ninety degrees?

Latitude must be between −90 and 90 inclusive; values outside that range are not clamped and are not billed.

Does the result include miles or travel time?

No. The contract answers latitude-longitude distance in kilometres only. Convert units yourself if you need miles, and use a routing engine for driving time.

Why can't I treat latitude and longitude as flat x and y?

Because a degree of longitude is not a fixed length: it shrinks from the equator toward the poles, so the same change in longitude covers very different ground in Quito and in Oslo. Measuring on a sphere avoids that stretch.

What is the longest distance the calculator can return?

For two exactly opposite points on the globe the result is close to π times 6371 kilometres, half the way around the sphere. Identical points return zero, and every other pair falls in between.

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/latitude-longitude-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/latitude-longitude-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.latitude_longitude_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.

The browser tool is free; successful API calls cost $0.002 per item. A latitude that exceeds ninety degrees fails with invalid_input instead of being clamped into a fake position.

What latitude-longitude distance on a sphere actually measures

This endpoint returns only kilometres, which is the unit people type into a search bar when they look for a latitude longitude distance calculator.

Input contract, coordinate ranges, and the ninety-degree latitude error

Latitude is the north-south coordinate and must lie in the closed interval from minus ninety to plus ninety. Longitude is the east-west coordinate and must lie in the closed interval from minus one hundred eighty to plus one hundred eighty. Clamping would invent a position the caller never sent and would make a downstream radius check look as if it had run on real GPS. Longitude outside plus or minus one hundred eighty is rejected the same way. Pair the kilometre with your own unit conversion if you need miles or metres; this product answers the latitude-longitude-distance question in kilometres and does not emit maps, bearings, or travel time. POST a JSON body with four required finite numbers in decimal degrees: lat1 and lon1 for the first point, lat2 and lon2 for the second. Each field may arrive as a JSON number or as a numeric string; missing fields, empty strings, and non-finite values fail with invalid_input that names the field, and those failures are not billed. If a latitude exceeds ninety degrees in either direction the task is rejected with a clear invalid_input message rather than silently clamping the pin onto a pole. A frequent client bug is swapping latitude and longitude when pasting a GeoJSON-style pair; the call may still succeed if both numbers happen to sit inside both ranges, but the kilometre result will not match the cities you intended, so keep lat as north-south and lon as east-west. Another pitfall is feeding projected metres or local grid offsets instead of geographic degrees; this API expects WGS84-style decimal degrees only. On success the body echoes the four coordinates, returns km rounded to six decimal places for stable goldens, restates earth_radius_km as 6371, and names the method in formula as haversine.

Where a kilometre great-circle API earns its keep

Use the prepaid API from workers, notebooks, and SDKs when servers need the same contract under KIT balance at $0.002 per successful item; validation failures, including a latitude that exceeds ninety degrees, never consume balance. Keep requests small, pin the rounded km field in tests, and you can recompute offline with the published radius and match the API. This is not drive distance, not a rhumb line, and not a cadastral geodesic. For everything between—dashboards, SLAs, and API filters—validate ranges, measure the great circle, return kilometres, done.

Which formula and Earth radius does this calculator use?

The spherical haversine formula with R = 6371 kilometres. It is not an ellipsoidal Vincenty or Karney geodesic, so polar flattening is ignored.

What does the latitude longitude distance calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →