Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Geohash

Turning a latitude and longitude into a short base32 string, demoing the p/moul/x/daily/geohash library.

The eight cells around ezs42

ezefx ezs48 ezs49
ezefr ezs42 ezs43
ezefp ezs40 ezs41

Each one is computed by walking exactly one cell from the centre and re-encoding. Every bound is an exact binary fraction, so the step lands on another centre rather than near one, and stepping back is the identity.

The antimeridian is not an edge of the world

z is the top right corner cell of the world. The cell east of it is b, the top left one, because longitude wraps. The classic lookup-table implementations report nothing there, which is a property of the tables and not of the globe.

Latitude genuinely stops, though, so z has no northern neighbour and Neighbors returns 5 cells rather than eight: b, 8, x, w, y.

Back to the overview.