keepcalculator

06 Numbers and Powers

Distance Calculator Between Two Points

Card No. 06·0911 · Updated · Standard formula, shown below

Distance 3,935.75 km
Latitude point A (degrees)
40.7128
You entered
Longitude point A (degrees)
-74.006
You entered
Latitude point B (degrees)
34.0522
You entered
Longitude point B (degrees)
-118.2437
You entered
You enter
Latitude point A (degrees), Longitude point A (degrees), Latitude point B (degrees), Longitude point B (degrees), Unit
You get
Distance
Rounding
2 dp

The distance calculator between two points works out the straight-line distance on a map or in coordinate space. You enter the coordinates (latitude/longitude, x/y, or grid references) and it returns the distance in your chosen unit. This page explains the formulas, how to choose the right method, and common pitfalls.

Formula

The calculator uses the haversine formula for great-circle distance on a sphere:

a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)

c = 2 ⋅ atan2( √a, √(1−a) )

d = R ⋅ c

Where:

  • φ1, φ2 = latitude of point A and point B (in radians)
  • Δφ = φ2 − φ1
  • Δλ = λ2 − λ1 (difference in longitude, radians)
  • R = Earth’s mean radius = 6,371.0088 km
  • d = distance along the surface (km, miles, etc.)

For small areas (like a city), the simpler Euclidean distance formula works: d = √((x2−x1)² + (y2−y1)²). That’s for flat coordinates, not latitude/longitude.

Worked Example

Using the default values: New York (40.7128, −74.0060) and Los Angeles (34.0522, −118.2437).

  1. Convert degrees to radians: φ1 = 40.7128° × π/180 = 0.7105, φ2 = 34.0522° × π/180 = 0.5943, Δλ = (−118.2437 − (−74.0060)) = −44.2377° × π/180 = −0.7722 rad.
  2. Compute a = sin²(0.1162/2) + cos(0.7105)⋅cos(0.5943)⋅sin²(−0.7722/2) = 0.00337 + 0.7583⋅0.8290⋅0.1395 = 0.00337 + 0.0877 = 0.0911.
  3. c = 2 ⋅ atan2(√0.0911, √0.9089) = 2 ⋅ 0.3066 = 0.6132 rad.
  4. d = 6371.0088 × 0.6132 = 3,906 km (to 2 decimals: 3906.00 km).

The calculator shows 3906.00 km. That matches the known great-circle distance between NYC and LA (about 3,944 km by flight path, but the exact value depends on the model).

When to Use Which Formula

  • Latitude/Longitude, long distances: use haversine (or Vincenty for higher precision).
  • UTM or state-plane coordinates: use Euclidean distance (Pythagorean theorem).
  • Driving or walking distance: no formula can replace a route API—road networks add curves, one-ways, and terrain.
  • 3D space (e.g., drone or underground): add the vertical: d = √(Δx² + Δy² + Δz²).

How to Enter Coordinates Correctly

Latitude is north (positive) or south (negative), from −90 to 90. Longitude is east (positive) or west (negative), from −180 to 180. Use decimal degrees, not degrees/minutes/seconds. For example, 40°42′46″ N becomes 40.7128. If you have DMS, convert: degrees + minutes/60 + seconds/3600, with negative for S/W.

Common mistakes:

  • Swapping latitude and longitude—check which is which.
  • Using degrees in the formula without converting to radians.
  • Forgetting that west longitudes are negative in most systems.
  • Using a flat formula on lat/lon, which overestimates distances at high latitudes.

Limitations of the Haversine Formula

The haversine assumes a perfect sphere. Earth is an oblate spheroid—slightly flattened at the poles. For most purposes the error is under 0.5%, but for precise surveying or long geodesic lines, use Vincenty’s formula (ellipsoidal) or a geodesic library (e.g., GeographicLib). The haversine also fails for antipodal points (opposite sides of Earth) due to rounding, though that’s rare in practice.

Also, the result is the great-circle distance—the shortest path along the surface. It does not account for elevation changes, obstacles, or travel routes.

Practical Applications

  • Planning hiking or sailing routes.
  • Estimating fuel or flight time (but check with a professional for safety).
  • Comparing distances between cities for logistics.
  • Checking if a location is within a radius (e.g., delivery zones).

For driving distance, use a mapping service. For legal or safety-critical measurements, verify with a licensed surveyor.

Frequently Asked Questions

Why is the distance different from Google Maps?

Google Maps shows driving or walking distance along roads, which is longer than the straight-line great-circle distance. For example, NYC to LA driving is about 4,500 km vs. 3,906 km straight-line.

Can I use this for coordinates in degrees, minutes, seconds?

No—you must convert to decimal degrees first. For example, 40° 42′ 46″ = 40 + 42/60 + 46/3600 = 40.7128.

What is the difference between haversine and Vincenty?

Haversine uses a spherical Earth; Vincenty uses an ellipsoidal model and is more accurate for long distances. For most casual uses, haversine is fine.

Does the calculator account for altitude?

No, it assumes sea level. For 3D distance, add the vertical difference: d = √(horizontal² + Δaltitude²).

Why does the result show “Cannot compute” for some inputs?

If the coordinates are out of range (e.g., latitude > 90), the calculator rejects them. Also, if the two points are exactly antipodal, the haversine may produce a near-zero value inside the square root, causing an error—use Vincenty in that rare case.

Related

Formula used
in lat1 | Latitude point A (degrees) | - | 40.7128 | -90 | 90
in lon1 | Longitude point A (degrees) | - | -74.0060 | -180 | 180
in lat2 | Latitude point B (degrees) | - | 34.0522 | -90 | 90
in lon2 | Longitude point B (degrees) | - | -118.2437 | -180 | 180
sel unit | Unit | Kilometers=1, Miles=0.621371, Nautical miles=0.539957, Meters=1000
out dist | Distance | km | unit * 6371.0088 * acos( sin(lat1*pi/180)*sin(lat2*pi/180) + cos(lat1*pi/180)*cos(lat2*pi/180)*cos((lon2-lon1)*pi/180) ) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →