Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 -> putStrLn $ "decoding geohash1: " ++ (show.decode) g
      Nothing -> putStrLn "error encoding"
  4. Create a geohash of another similar latitude-longitude coordinate pair as follows:

    let geohash2 = encode 10 (37.175, -125.419)
    putStrLn $ "geohash2...