Interactive calculators for the formulas underpinning location-aware applications — Haversine distance, bearing, destination point, tile addressing, and viewport projection.
Great-circle distance between two lat/lng points on a sphere. Accurate to within 0.5 % globally (Earth is slightly oblate, but the spherical model is more than sufficient for game-scale distances).
a = sin²(Δlat/2) + cos(lat₁)·cos(lat₂)·sin²(Δlng/2)
d = 2R · atan2(√a, √(1−a)) where R = 6 371 000 m
Forward azimuth (initial bearing) from A to B. Also computes the destination point reached by travelling a given distance and bearing from A — used for spawning world-space objects at known offsets from the player.
Given a lat/lng and zoom level, compute the tile address, the pixel offset within that tile, and the number of tiles needed to cover a given radius — for pre-caching.
Converting a world lat/lng to a canvas pixel, given a centre position, zoom level, and canvas size. This is the core transform needed to render any world object onto a flat 2D map.
px = (lng + 180) / 360 × tileSize × 2^Zpy = (1 − ln(tan(lat·π/180) + sec(lat·π/180)) / π) / 2 × tileSize × 2^Z