Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions reverse-geocoding.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ library
hs-source-dirs: src
default-language: Haskell2010

test-suite network-test
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: NetworkTest.hs
build-depends: base,
reverse-geocoding

source-repository head
type: git
location: https://github.com/jcristovao/reverse-geocoding
7 changes: 5 additions & 2 deletions src/Data/Geolocation/Reverse/Providers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.Aeson
import Data.Aeson.Types
import Control.Monad (join)
import qualified Data.Text as T
import Text.Printf

import Data.Geolocation.Reverse.Types

Expand All @@ -41,8 +42,8 @@ openStreetMapUrl (Latitude mlat) (Longitude mlon) = do
return $ "http://nominatim.openstreetmap.org/reverse"
<> "?format=json"
<> "&zoom=18"
<> "&lat=" <> show lat
<> "&lon=" <> show lon
<> "&lat=" <> formatFixed lat
<> "&lon=" <> formatFixed lon


getPostCodeText :: Suburb -> Maybe Suburb
Expand Down Expand Up @@ -77,3 +78,5 @@ openStreetMapParser o =
<|?> (o .:? "street")
)
<*> o .:? "postcode"

formatFixed n = printf "%.6f" n
15 changes: 15 additions & 0 deletions tests/NetworkTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Data.Geolocation.Reverse
import Data.Geolocation.Reverse.Types

main = do

-- all we're going to do is get a location and
-- check we don't crash.
l <- getLocationInfoDef (Latitude (Just 5)) (Longitude (Just 5))
print l

-- regression test for extremely small numbers that
-- were being rendered using invalid exponential
-- notation.
l2 <- getLocationInfoDef (Latitude (Just 0.0005)) (Longitude (Just 0.0005))
print l2