CHAPTER 08
Bearings, headings, and azimuths
Computing the angle from one point to another, normalizing to compass headings, and why bearings change along a path.
When you know two geographic points, distance is one useful quantity — but direction is equally important. A bearing tells you which compass direction to face to look from one point toward another. It's the foundation of navigation, drone flight paths, sector queries ("show me restaurants to the north of me"), and directional UI elements like compass indicators.
Bearing, heading, and azimuth all mean the same thing in this context: the angle from north, measured clockwise, from 0° (north) to 360°. North = 0°, East = 90°, South = 180°, West = 270°. The term "bearing" is common in navigation; "azimuth" in astronomy and surveying; "heading" in aviation.
The bearing (or forward azimuth) is the angle, measured clockwise from north, from one point toward another. Use the calculator below to build intuition before the formula.
Bearing calculator
From (A)
To (B)
Bearing A → B
314.05°
NW (314° from north)
Initial bearing formula
The result is in radians, in the range . Convert to degrees and normalize to :
The +360 before mod 360 handles negative angles from arctan2 — it shifts the range from [-180, 180] to [0, 360) without changing positive values.
function bearing(lat1, lon1, lat2, lon2) {
const toRad = d => d * Math.PI / 180;
const φ1 = toRad(lat1), φ2 = toRad(lat2);
const Δλ = toRad(lon2 - lon1);
const y = Math.sin(Δλ) * Math.cos(φ2);
const x = Math.cos(φ1) * Math.sin(φ2) -
Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ);
return (Math.atan2(y, x) * 180 / Math.PI + 360) % 360;
}
Continue reading "Bearings, headings, and azimuths"
You've reached the end of the free preview. Unlock all 22 paid chapters, including distance math, bearings, polygons, spatial indexing, and 3D map rendering — plus a downloadable PDF and the companion code repo.
- All 22 paid chapters with worked examples
- Downloadable PDF for offline reading
- Companion GitHub repo (JavaScript + Python)
- Free updates for life
Multiple payment options including Wise, PayPal, and bank transfer.
Related chapters
- Distance on a sphere — Haversine and friends — the distance to go with the bearing
- Destination points — moving on a sphere — combine bearing and distance to find destination
- Routing on road networks — bearings as an A* heuristic