Geohash
Geohashes are a way of encoding lat/lon points as strings. It works by reducing the two-dimensional longitude and latitude data into a one-dimensional string of letters and digits.
Algorithm
Take the latitude and longitude ranges: latitude between -90 to 90 and longitude between -180 to 180.
Determine whether the given latitude is in the first half or the second half of the latitude range, and whether the given longitude is in the first half or the second half of the longitude range. For each, output 0 if it's in the first half or 1 if it's in the second half.
Now consider only the half-range that the point is in, and repeat the process. For each iteration, append 0 or 1 to the output based on which half the point is in.
Continue this process until you've reached the desired precision.
Interleave the bits from the latitude and longitude, starting with the longitude, to get the final Geohash in binary.
Convert the binary Geohash to base32 to get the final Geohash string.
Precision Table
Geohash has 12 precisions, we only interested in 4-6.
1
5000km x 5000km (size of earth)
2
1252km x 624km
3
156km x 156km
4
39km x 19km
5
4.9km x 4.9km
6
1.2km x 0.6km
7
152.9m x 152m
8
38m x 19m
9
4.8m x 4.8m
10
1.2m x 59.5cm
11
14.9cm x 14.9cm
12
3.7cm x 1.9cm
To find geohash length that fit the radius, we need the maximum geohash length that cover the entire region for best accuracy.
Last updated