Computing a Geohash for location coordinates
A Geohash is a practical encoding of latitude-longitude coordinates. It does not behave like a typical hash function since minor changes in location only produce minor changes in the output digest. Geohash allows efficient proximity search and arbitrary precision determined by the specified length of the digest.
Getting ready
Install the Geohashing library as follows:
$ cabal install geohash
How to do it…
Import the
Geohash
library as follows:import Data.Geohash
Create a geohash of a latitude-longitude coordinate pair as follows:
main = do let geohash1 = encode 10 (37.775, -122.419) putStrLn $ "geohash1 is " ++ (show geohash1)
Display the geohash using the following code snippet:
case geohash1 of Just g -> putStrLn $ "decoding geohash1: " ++ (show.decode) g Nothing -> putStrLn "error encoding"
Create a geohash of another similar latitude-longitude coordinate pair as follows:
let geohash2 = encode 10 (37.175, -125.419) putStrLn $ "geohash2...