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…

  1. Import the Geohash library as follows:
    import Data.Geohash
  2. 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)
  3. Display the geohash using the following code snippet:
    case geohash1 of Just g -> ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.