A geohash is a convenient way of expressing a location (anywhere in the world) using a short alphanumeric string, with greater precision obtained with longer strings.
A geohash actually identifies a rectangular cell: at each level, each extra character identifies one of 32 sub-cells.
The cell sizes of geohashes of different lengths are as follows; note that the cell width reduces moving away from the equator (to 0 at the poles):
Geohash length | Cell width | Cell height | |
---|---|---|---|
1 | ≤ 5,000km | × | 5,000km |
2 | ≤ 1,250km | × | 625km |
3 | ≤ 156km | × | 156km |
4 | ≤ 39.1km | × | 19.5km |
5 | ≤ 4.89km | × | 4.89km |
6 | ≤ 1.22km | × | 0.61km |
7 | ≤ 153m | × | 153m |
8 | ≤ 38.2m | × | 19.1m |
9 | ≤ 4.77m | × | 4.77m |
10 | ≤ 1.19m | × | 0.596m |
11 | ≤ 149mm | × | 149mm |
12 | ≤ 37.2mm | × | 18.6mm |
Nearby locations generally have similar prefixes, though not always: there are edge-cases straddling
large-cell boundaries; in France, La Roche-Chalais (u000) is just 30km from Pomerol (ezzz).
A reliable prefix search for proximate locations will also search prefixes of a cell’s 8 neighbours.
(e.g. a database query for results within 30-odd kilometres of Pomerol would be
SELECT * FROM MyTable WHERE LEFT(Geohash, 4) IN ('ezzz', 'gbpb, 'u000', 'spbp', 'spbn', 'ezzy', 'ezzw', 'ezzx', 'gbp8')
.
Whether this would offer significant (or any) performance gains over a latitude/longitude
bounding box search I’ve yet to check.
Database applications might be limited, but geohashes may certainly be easier to communicate than latitude-longitude values: while not exactly memorable, ‘dr5.ru6.j6v’ might be easier to read out to someone than the equivalent ‘40.74879,-73.98547’.
What other applications do people have for geohashes?
Fun geohashes: ‘sunny’ is in Saudi Arabia, ‘fur’ in Greenland, ‘reef’ in the Coral Sea, ‘geek’ in Iceland (sadly, ‘eu’ is in the Maghreb, not Europe, and ‘queen’ [Priscilla?] is lost in the Australian desert).
See below for the JavaScript source code, also available on GitHub. These functions should be simple to translate into other languages if required. It’s also available from the jsDelivr CDN or as an npm package for Node.js.
I offer these scripts for free use and adaptation to balance my debt to the open-source info-verse. You are welcome to re-use these scripts [under an MIT licence, without any warranty express or implied] provided solely that you retain my copyright notice and a link to this page.
If you have any queries or find any problems, contact me at ku.oc.epyt-elbavom@oeg-stpircs.
© 2014–2019 Chris Veness