MapMath

CHAPTER 01

Why map math matters

What this guide covers, the notation we'll use, and why understanding map math matters even when libraries hide it.

4 min readfree

Every time your phone shows "0.4 km away" under a coffee shop, draws a blue route polyline, or tells you a delivery driver is "3 minutes out," map math is doing the work. As a developer, knowing map math is the difference between:

  • Calling turf.distance(a, b) and hoping for the best, and
  • Knowing why the answer is a few meters off, when it matters, and how to fix it.

This guide assumes you can write code, do basic algebra, and remember roughly what sin and cos do. We'll build everything else from scratch.

What is a coordinate?

optional — skip if familiarrefresher

Skip to What we're solving if you're already comfortable with lat/lon.

A geographic coordinate is a pair of two angles that together uniquely identify any point on Earth's surface:

  • Latitude (φ) — how far north or south you are from the equator, ranging from −90° (South Pole) to +90° (North Pole)
  • Longitude (λ) — how far east or west you are from the Prime Meridian (through Greenwich, London), ranging from −180° to +180°
const lahore  = { lat:  31.5204, lon:  74.3587 };
const london  = { lat:  51.5074, lon:  -0.1278 };
const sydney  = { lat: -33.8650, lon: 151.2090 };
const newYork = { lat:  40.7128, lon: -74.0060 };

Negative latitude = south of the equator. Negative longitude = west of Greenwich. That's the entire system. Everything else in this guide — projections, distances, tile coordinates — is derived from these two numbers.

Why angles, not metres? Because Earth is a sphere. You can't describe a position on a sphere with a flat x/y grid. Angles give you a reference system that works anywhere on the surface, regardless of orientation.

What we're solving

Maps live at the intersection of three problems:

  1. The Earth is round, but screens are flat.
  2. Coordinates are angular (degrees), but distances are linear (metres).
  3. At scale, even tiny errors compound — a 0.5° rounding on a flight path puts you in a different country.

The root of all of these is that a location on Earth is described as two angles: how far north/south of the equator (latitude, φ), and how far east/west of the Greenwich meridian (longitude, λ). Drag the globe below to see how those angles sit on the sphere.

interactive · drag to rotate

φ = 31.52°N  ·  λ = 74.36°E

φ arc = latitude angle from equator
λ arc = longitude angle from prime meridian

The bright arcs show the angles, not the distances. φ is measured from the equatorial plane; λ is measured along the equatorial plane from the prime meridian. Every formula in this guide is derived from those two angles.

Why libraries aren't enough

Mapping libraries like Mapbox, Leaflet, and deck.gl abstract most of this. So why learn the underlying math?

1. Edge cases bite you. The antimeridian (the ±180° line in the Pacific) breaks naïve distance and bounding-box calculations. The poles are degenerate points in most projections. Libraries often handle the common case, not the edge case.

2. Performance. When you need to filter 100,000 points within a radius, calling a library function 100,000 times is slow. Understanding the math lets you write a spatial index that does it in microseconds.

3. Custom visualisations. Standard map tiles only go so far. 3D terrain, custom projections, flight-path arcs — these require writing the math yourself.

4. Debugging. When coordinates are off by 0.01°, or a polygon appears on the wrong continent, you need to know what question to ask. That requires understanding what the numbers mean.

Notation we'll use

SymbolMeaning
φ (phi)Latitude
λ (lambda)Longitude
REarth's radius (≈ 6,371,008.8 m mean)
Δ"Change in" (delta) — e.g. Δφ = φ₂ − φ₁
θBearing / angle from north

All angles are in radians in formulas unless explicitly noted. Most APIs give you degrees, so you'll convert constantly:

radians=degrees×π180\text{radians} = \text{degrees} \times \frac{\pi}{180} degrees=radians×180π\text{degrees} = \text{radians} \times \frac{180}{\pi}
optional — skip if familiarrefresher

Why radians? Because of how arc length works on a circle. If a circle has radius RR, an arc subtending angle θ\theta radians has length s=Rθs = R\theta. With degrees, that formula needs an awkward π/180\pi/180 factor everywhere. Radians eliminate the clutter — they're the natural unit for geometry on a sphere.

The key anchors: 180° = π rad, 90° = π/2 rad, 1 rad ≈ 57.3°. Those three cover 90% of the mental arithmetic you'll do while debugging.

The conversion is mechanical but worth building intuition for. Use the dial below — drag the point or click a preset.

interactive · drag the point

0°90°180°270°

Degrees

45°

Radians

0.7854

45 × π ÷ 180 = 0.7854

Before you continue

optional — skip if familiarrefresher

Quick self-check before moving on:

  • What are the coordinates of a point on the equator, due east of Greenwich? (0°, 90°)
  • Can latitude ever be 100°? (No — maximum is 90°)
  • Which axis does longitude move along — north-south or east-west? (East-west)
  • What is Δφ if you move from 10°N to 35°N? (25° = 0.436 rad)

If those feel comfortable, the rest of the guide will follow naturally.

References

2 sources
  1. [1]

    Snyder, J.P. (1987).

    Map Projections: A Working Manual.”

    USGS Professional Paper 1395, United States Government Printing Office

    The canonical reference for map projection mathematics, covering every major projection with full derivations.

  2. [2]

    Torge, W. & Müller, J. (2012).

    Geodesy (4th ed.).”

    De Gruyter

    Comprehensive treatment of geodetic theory — coordinate systems, datums, and the shape of the Earth.