MapMath

The math behind
every map
you'll ever build.

A developer's reference to Map mathematics — compiled by Umar Farooq

lat/lon, Web Mercator, 3D terrain, camera matrices, building extrusion. Every formula has runnable JavaScript and a worked numeric example.

ProjectionsHaversineTile math3D terrainCamera mathBuildingsRoutingSpatial index
Globe · WGS 84 · Great-circle arcs
5 cities·Great-circle routes
Great circle CitiesCh. 02, 04
Chapter 04 · Haversine Distance FormulaR = 6 371 km

a = sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2)

d = 2R · arcsin(√a)

London → New York0 km
LondonNew York

Ch 02 · Web Mercator

x = R · λ

y = R · ln tan(π/4 + φ/2)

EPSG:3857

Ch 03 · Tile Index

x = ⌊(λ+180)/360 · 2ᶻ⌋

y = ⌊(1−ln(tan φ+sec φ)/π)/2·2ᶻ⌋

z=12 → 4 096² tiles

haversine.jsChapter 04
function haversine(lat1, lon1, lat2, lon2) {
const R = 6371, toRad = d => d * Math.PI / 180;
const φ1 = toRad(lat1), φ2 = toRad(lat2);
const Δφ = toRad(lat2 - lat1);
const Δλ = toRad(lon2 - lon1);
const a = Math.sin(Δφ/2)**2
+ Math.cos(φ1) * Math.cos(φ2)
* Math.sin(Δλ/2)**2;
return 2 * R * Math.asin(Math.sqrt(a));
}
lat-lng-to-tile.jsChapter 03
function latLngToTile(lat, lon, z) {
const n = 2 ** z;
const x = Math.floor((lon + 180) / 360 * n);
const r = lat * Math.PI / 180;
const y = Math.floor(
(1 - Math.log(Math.tan(r) + 1/Math.cos(r))
/ Math.PI) / 2 * n);
return { z, x, y };
}

Map math you'll actually use.
Not theorems you'll forget.

Every formula has a worked numeric example and runnable JavaScript. The caveats are included too: antimeridian wrapping, the GeoJSON lon/lat trap, when Haversine isn't accurate enough.

  • 01

    Coordinate systems

    Lat/lon, datums, EPSG codes, decimal degrees, and how big a degree really is.

  • 02

    Map projections

    Mercator math, Web Mercator (EPSG:3857), and why Greenland looks continent-sized.

  • 03

    Tile & pixel math

    The slippy map system, z/x/y tiles, world pixel coordinates, resolution at zoom.

  • 04

    Distance & bearings

    Haversine, Vincenty, great-circle vs rhumb-line, initial and final bearings.

  • 05

    Spatial indexing

    Geohash, quadtrees, R-trees, S2, H3 — when each one is the right answer.

  • 06

    Practice problems

    Eight worked exercises with full solutions, from simple conversions to spherical polygon area.

Questions buyers usually ask

What format do I get?+
Read it in the browser at mapmath.dev, plus a downloadable PDF for offline use. You'll receive email updates whenever a new chapter or calculator is added.
Is there a sample?+
Yes — the first 5 chapters are free, no signup required. Start with the introduction or jump straight to coordinate systems and projections.
Will updates be free?+
Yes. Lifetime access includes all future chapters, calculator tools, and revisions. Pay once, keep it forever.
Can I get a refund?+
30 days, no questions asked. Email me through the address in the footer and I'll refund through the same channel you paid with.
Does Wise / PayPal work in my country?+
Wise covers 80+ countries; PayPal covers 200+. If your country isn't supported by either, email me and we'll arrange an alternative (direct bank transfer or another route).
What frameworks does the code work with?+
Vanilla JavaScript and Python — no framework lock-in. The JS code runs in React, Vue, Svelte, Node, or no framework at all. The Python code is plain Python (no Django / FastAPI dependencies).
How much math background do I need?+
High-school trigonometry. Every formula is explained from first principles — if you remember sin / cos / atan2, you'll be fine. The 3D chapters introduce linear algebra (matrices for camera projection), with all the math explained in context.
Why is the price in USD if you're based in Pakistan?+
USD is the de facto currency for digital products globally — buyers from any country understand the price instantly. You pay in your local currency through Wise / PayPal / bank transfer; they handle the conversion at near-mid-market rates.

One price, lifetime access.

Pay once, keep it forever. When the guide gets updated, you get the changes automatically.

Full access

$39

USD · one-time

  • All 27 chapters (5 free + 22 paid)
  • Downloadable PDF for offline reading
  • Companion code repo (JS + Python)
  • Free updates for life
  • Email support
Get Full Access — $39

Wise · PayPal · Bank transfer · Email

Student or researcher? Email for a discount — I'll sort you out.