Skip to content
dz / distance-between-coordinates-km

Distance between two coordinates in km

Enter two latitude/longitude points – the distance as the crow flies is shown in km, with bearings and the route on the map.

/dist
A

B

Units
Distance
–

Want to see where your IP address places you? getmy-ip.com ↗

Map Click to place
· drag the markers to move them

The line is the shortest path on the Earth's surface (geodesic) – on a flat map it bends towards the pole.

The haversine formula

For a quick estimate the Earth is treated as a sphere with radius R ≈ 6,371 km. With latitudes φ and longitudes λ in radians:

a = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2)
d = 2R · atan2(√a, √(1−a))

// JavaScript
function haversineKm(lat1, lon1, lat2, lon2) {
  const r = Math.PI / 180, R = 6371.0088;
  const a = Math.sin((lat2 - lat1) * r / 2) ** 2 +
    Math.cos(lat1 * r) * Math.cos(lat2 * r) * Math.sin((lon2 - lon1) * r / 2) ** 2;
  return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}

The sphere is off by up to about 0.5 %. The main result above is computed on the WGS84 ellipsoid GPS uses, accurate to millimetres; the haversine value and its difference are listed below it. Paris → Berlin, the example, is about 880 km.

Questions

Why does my route planner show a longer distance?

Route planners measure along roads. This is the distance "as the crow flies" – the shortest path over the Earth's surface.

In which format do I enter coordinates?

Latitude first, then longitude, as decimal degrees (48.8566, 2.3522), degrees-minutes-seconds, or simply a Google Maps / OpenStreetMap link.

How do I get miles?

Switch the unit to miles or nautical miles; all values update. One mile is 1.609344 km, one nautical mile 1.852 km.

▸ About this tool

About the GPS Distance Calculator

Introduction

How far is it between two places "as the crow flies", and in which direction do you have to set off? This tool measures the distance and bearing between any two GPS coordinates on the Earth's surface and draws the route on a map. It is handy for checking geolocation data, estimating flight and sailing distances, validating the output of location APIs, or simply settling an argument about which city is closer.

How to use it

  1. Enter point A and point B in almost any notation – decimal degrees (50.0875, 14.4213), degrees-minutes-seconds (50°5'15"N 14°25'17"E), degrees with decimal minutes (N 50 5.25 E 14 25.28), a geo: URI or a Google Maps / OpenStreetMap link.

  2. Or click the map: the first click places the selected point, the next one the other. Drag either marker to fine-tune it, or use My location.

  3. Read the distance in kilometres, miles or nautical miles together with the bearings, the midpoint and the alternative constant-bearing route. Every value has a copy button, and the address bar keeps both points so you can share the exact measurement.

Short links: develzone.org/dist, /distance, /haversine and /bearing. Pasting a coordinate pair into the search box on the home page opens it here as point A.

Haversine or ellipsoid?

The well-known haversine formula treats the Earth as a perfect sphere with a radius of 6,371 km. It is simple and good to within about 0.5 %. The Earth, however, is slightly flattened – about 21 km shorter from pole to pole than across the equator. This tool therefore also computes the exact distance on the WGS84 ellipsoid, the reference shape used by GPS, using Charles Karney's geodesic algorithms (2013), which are accurate to a few nanometres for any two points on Earth. Both results are shown, along with how much the haversine estimate is off.

Bearings and routes

  • Initial bearing – the compass direction you start in at A (0° = north, 90° = east).

  • Final bearing – the direction you are heading when you arrive at B. On a long great-circle route it differs from the initial bearing: a flight from New York to London leaves heading north-east and arrives heading east-south-east.

  • Great circle (geodesic) – the shortest path, drawn on the map. On a flat Mercator map it looks curved towards the pole, which is why transatlantic flights pass over Greenland and Iceland.

  • Rhumb line – a route that keeps one constant compass course. It is a straight line on a Mercator chart and easier to steer, but longer, especially on long east–west legs at high latitudes.

Good to know

  • Latitude comes first, longitude second. Values west of Greenwich and south of the equator are negative (London: 51.5074, -0.1278).

  • One nautical mile is exactly 1,852 m – roughly one minute of latitude. One statute mile is 1,609.344 m.

  • The result is the distance over the Earth's surface at sea level; it ignores roads, terrain and altitude.

  • Have coordinates in degrees, minutes and seconds? Convert them with Degrees ⇄ decimal. Coordinates hidden in a photo can be read with the Exif reader.

Privacy

All calculations run in your browser. Your location is only used if you press My location, never leaves your device and is not stored. Map tiles are loaded from OpenStreetMap.

❯ Esc
↑ ↓ select ↵ open Shift ↵ new line