A geohash library for Elm.
To install it in your development directory:
elm install andys8/elm-geohash
To use it from your code:
import Geohash
geohash = Geohash.encode -25.38262 -49.26561 8
Thanks to Ning Sun for the JavaScript implementation.
The geohash preserves spatial locality so that points close to each other in space are close to each other on disk. This is because the arrangement of the result is comparable with space filling Z-order curves. The length of geohashes can be chosen individually and depending on the degree of accuracy. Characters at the end are less significant. Truncating the geohash can be used to cover larger areas. In fact this can be used to build range queries based on the prefix of the primary key.
The geohash is constructed bitwise. The range of both dimensions will be cut in half. If the target point is located in the greater half of the range, the value of the first bit is 1
. Otherwise it’s 0
. The example longitude 11.53..°
would result in a 1-bit
as first value because it’s part of range [0°, +180°]
and not [-180°, 0°)
. This binary partitioning approach will be repeated alternately for both axes (beginning with longitude). Because the encoding is weaving the bits together, the geohash has the spatial locality property.