Bearing and Distance Calculator

Enter two positions in decimal degrees. Everything below is derived by trigonometry on the two coordinate pairs; nothing is looked up and nothing leaves the page. The default pair is deliberately one you can check by hand — see the closed-form cases further down.

kilometres, great circle

The earth model this uses, stated plainly

Every number above assumes a sphere of radius 6 371.0088 km — the arithmetic mean of the WGS-84 semi-axes, the conventional choice when a single radius is needed. Conversions are exact by definition: one nautical mile is 1 852 m, and one statute mile is 1 609.344 m.

The Earth is not a sphere. WGS-84 describes an oblate ellipsoid whose polar radius is shorter than its equatorial radius by roughly one part in three hundred, so no single radius can be right everywhere. A great-circle distance on a sphere is therefore an approximation to a geodesic, not a geodesic. The discrepancy is systematic rather than random — it varies with latitude and with the orientation of the leg, being largest for long east–west legs at high latitude — which means it does not average out over a set of routes.

For planning distances, route comparison, ordering candidate depots by proximity, or sizing a fuel or transit estimate before detailed routing, a spherical figure is entirely adequate and its error is far smaller than the routing allowance you will add anyway. For anything where the difference between a sphere and an ellipsoid would change a decision — survey, precision navigation, boundary determination — use an ellipsoidal geodesic solver instead. This page is not that, and says so rather than quietly implying otherwise.

Why haversine rather than the law of cosines

Both formulas give the central angle between two points on a sphere, and algebraically they agree. Numerically they do not.

The spherical law of cosines finishes with an arc-cosine. Near zero separation its argument approaches one, where the cosine curve is flat, so a rounding error in the argument becomes a much larger error in the angle. In double precision this shows up, on the reference implementation used to check this page, as a spurious separation of roughly a tenth of a metre between two points that are in fact identical — small in absolute terms, and quite capable of putting a non-zero number where a zero belongs.

The haversine formula is built from half-angle sines and finishes with atan2(√a, √(1−a)), which stays well conditioned as the separation goes to zero. It degrades instead at the antipodal end, where the two points are diametrically opposite, and that case is degenerate for a different and more interesting reason: infinitely many great circles connect antipodal points, so the distance is well defined and the bearing is not. The tool flags it rather than printing an arbitrary azimuth.

Initial bearing, final bearing, and why they differ

A great circle is the shortest path on a sphere, and except along the equator or a meridian it does not cross successive meridians at the same angle. So the azimuth changes continuously along the route. The initial bearing is the azimuth at the point of departure; the final bearing is the azimuth on arrival. On a long leg they can differ by a great deal, and the gap is the whole reason a great-circle track has to be flown or sailed as a series of legs rather than as one heading.

A course held at a constant bearing is a rhumb line, which is a different and always longer path. It is easier to steer and is not what this page computes. If you take the initial bearing and hold it, you will not arrive.

Both bearings are reported clockwise from true north, in the range 0° to 360°. True north, not magnetic — magnetic variation is a local, time-varying quantity that has to come from a model of the geomagnetic field, and inventing one here would be worse than omitting it.

The degenerate cases, and what this page does about them

Identical points. Distance zero, bearing undefined. Reported as such rather than as a bearing of zero, which would be a direction rather than an absence of one.

Antipodal points. Distance is half the circumference; every direction is equally shortest. The page reports the distance and flags the bearing as non-unique.

Departing from a pole. At a pole the local north direction is undefined, so a bearing needs a convention. The one used here is the ordinary geographic one: every departure from the north pole is due south, and every departure from the south pole is due north. The general formula does not produce this on its own, so it is handled explicitly — and both cases are in the self-test.

Crossing the antimeridian. No special handling is needed. Longitude enters the formula only through sines and cosines of the difference, which wrap naturally. A leg from 179.99° E to 179.99° W is correctly short, not almost a full circumference, and that case is in the self-test too.

What the self-test checks

The note inside the panel is written by a suite that runs when the page loads. It covers twenty reference pairs, several of which have closed-form answers that can be verified with a pencil:

Four malformed inputs are also checked, to confirm they are rejected rather than coerced into a plausible-looking answer.

Before the JavaScript was written, the same formulas were implemented separately and cross-checked three ways: haversine, the spherical law of cosines, and a vector formulation using cross and dot products with a local east–north frame for the bearing — the last of which shares no algebra with the first. Across every case the three agreed to within nanometres on distance and to well below a millionth of a degree on bearing, with the single exception noted above: the law of cosines on a zero-length leg, which fails in exactly the way its conditioning predicts.

If any case fails, the panel says so and the outputs are blanked. A calculator that is quietly wrong is worse than no calculator, because it is trusted.