Geohash
Geohashing is a way to encode geographic coordinates (latitude and longitude) into short strings of letters and numbers. Gustavo Niemeyer created it in 2008. For example, San Francisco, at 37.7564, -122.4016, is written as 9q8yy9mf. It's like a very precise postal code: instead of 2 long numbers with decimals, 8 characters that say where you are.
A geohash is a hierarchical spatial index using a 32-symbol alphabet (Base-32). The first character picks 1 of 32 cells of the world. That cell splits into another 32, and the second character picks one of them. So each extra character shrinks the cell until the needed precision is reached. It's like finding an address: country, state, city, neighborhood, block; each step narrows the area.
Geohash guarantees that 2 points are closer if their geohashes share a longer prefix: the same first characters. For example, 9q8yy9mf and 9q8yy9vx share 9q8yy9, so they're a few meters apart. This lets you find nearby places by comparing strings, which databases do very fast with an index. It's like 2 addresses with the same country, city, neighborhood and street: they're surely close.
The geohash's length defines the cell size. With 1 character, the cell measures about 5,000 km; with 5, about 4.89 km; with 6, 1.22 by 0.61 km; with 8, 38 by 19 meters; with 12, about 37 millimeters. More characters, more precision. It's like a map's zoom: each level shows a smaller area in more detail.
Geohash also helps give some anonymity: there's no need to show the user's exact location, a short geohash saying only which area they're in is enough. For example, with 5 characters you only know they're in a cell of about 5 km. It's like saying «I live in Brooklyn» instead of giving your address: others know the area, not your house.
Geohash is used to store a location in a database simply, to share it on social media as part of a URL (it's easier to remember than latitude and longitude) and to find a point's nearest neighbors by comparing strings with an index. Databases like MySQL, Redis, Amazon DynamoDB and Google Cloud Firestore support it. It's like a locker code: short, easy to pass around and sortable.
