reverse-geocoding 0.2 → 0.2.1
raw patch · 4 files changed
+35/−13 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Geolocation.Reverse.Types: getCity :: City -> Text
+ Data.Geolocation.Reverse.Types: getPostcode :: Postcode -> Text
+ Data.Geolocation.Reverse.Types: getStreet :: Street -> Text
+ Data.Geolocation.Reverse.Types: getSuburb :: Suburb -> Text
Files
- reverse-geocoding.cabal +1/−1
- src/Data/Geolocation/Reverse.hs +12/−3
- src/Data/Geolocation/Reverse/Providers.hs +18/−5
- src/Data/Geolocation/Reverse/Types.hs +4/−4
reverse-geocoding.cabal view
@@ -1,5 +1,5 @@ name: reverse-geocoding-version: 0.2+version: 0.2.1 synopsis: Simple reverse geocoding using OpenStreeMap description: Simple reverse geocoding using OpenStreeMap homepage: https://github.com/jcristovao/reverse-geocoding
src/Data/Geolocation/Reverse.hs view
@@ -2,10 +2,19 @@ -- | This very simple module returns a Maybe Location info for a set -- of coordinates. ----- Right now only one provider is given (OpenStreeMap), and the Suburb/Street--- parsing could be improved, but this is enough for our needs.+-- Right now only one provider is given (OpenStreeMap), please feel+-- free to add more. ----- Feel free to contribute!+-- We use this for a very coarse geographic categorization, so+-- the following equivalences hold:+--+-- City : city \<|> village \<|> town \<|> hamlet \<|> county+--+-- Suburb: suburb \<|> hamlet \<|> postcode \<|> town+--+-- Street: road \<|> street+--+-- All contribuitions are welcomed! module Data.Geolocation.Reverse where import Control.Lens
src/Data/Geolocation/Reverse/Providers.hs view
@@ -50,17 +50,30 @@ rest = T.dropWhile (\c -> isDigit c || isSpace c || (c == '-')) txt in if T.null rest then Nothing else Just (Suburb rest) -(<||>) :: Parser (Maybe a) -> Parser (Maybe a) -> Parser (Maybe a)-pa <||> pb = do+(<|?>) :: Parser (Maybe a) -> Parser (Maybe a) -> Parser (Maybe a)+pa <|?> pb = do a <- pa if isJust a then pa else pb+infixl 3 <|?> + -- Not all records have suburb defined, but some have it written in the post code -- This function tries to extract if from the post code if available. openStreetMapParser :: Object -> Parser ParsedLocationInfo openStreetMapParser o = ParsedLocationInfo <$> o .: "country_code"- <*> (o .: "city" <|> o .: "village")- <*> ((o .:? "suburb") <||> fmap (join . fmap getPostCodeText) ( o .:? "postcode"))- <*> ((o .:? "road") <||> (o .:? "street"))+ <*> ( o .: "city"+ <|> o .: "village"+ <|> o .: "town"+ <|> o .: "hamlet"+ <|> o .: "county"+ )+ <*> ( (o .:? "suburb")+ <|?> (o .:? "hamlet")+ <|?> (fmap (join . fmap getPostCodeText) ( o .:? "postcode"))+ <|?> (o .:? "town")+ )+ <*> ( (o .:? "road")+ <|?> (o .:? "street")+ ) <*> o .:? "postcode"
src/Data/Geolocation/Reverse/Types.hs view
@@ -19,10 +19,10 @@ deriving (Eq,Ord,Show,Read,FromJSON,ToJSON) -- | /Output types/-newtype City = City T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)-newtype Suburb = Suburb T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)-newtype Street = Street T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)-newtype Postcode= Postcode T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)+newtype City = City { getCity :: T.Text } deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)+newtype Suburb = Suburb { getSuburb :: T.Text } deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)+newtype Street = Street { getStreet :: T.Text } deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)+newtype Postcode= Postcode { getPostcode :: T.Text } deriving (Eq,Ord,Show,Read,FromJSON,ToJSON) -- Booo: orphan instances instance ToJSON CountryCode