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.
a = sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2)
d = 2R · arcsin(√a)
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
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));}
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.
27 chapters, end to end.
Why map math matters
What this guide covers, the notation we'll use, and why understanding map math matters even when libraries hide it.
The shape of the Earth
Sphere, ellipsoid, geoid — three models, three answers, and which one you actually need for app development.
Coordinate systems: latitude and longitude
Latitude and longitude explained — decimal vs DMS notation, WGS84 and EPSG:4326, datum shifts, and how big a degree actually is in metres.
Map projections — flattening the globe
Why every flat map lies, the math behind Web Mercator and equal-area projections, and how to pick the right projection for your use case.
Web Mercator and tile math
How every web map (Google, OSM, Mapbox) tiles the world, with the formulas to convert lat/lon to tile coordinates.
Pixel and world coordinates
World pixels and screen pixels: the coordinate system behind every marker, overlay, and mouse-to-lat-lon conversion at any zoom level.
Questions buyers usually ask
What format do I get?+
Is there a sample?+
Will updates be free?+
Can I get a refund?+
Does Wise / PayPal work in my country?+
What frameworks does the code work with?+
How much math background do I need?+
Why is the price in USD if you're based in Pakistan?+
One price, lifetime access.
Pay once, keep it forever. When the guide gets updated, you get the changes automatically.
$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
Wise · PayPal · Bank transfer · Email
Student or researcher? Email for a discount — I'll sort you out.