google-static-maps 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+84/−35 lines, 4 filesdep +aesondep +double-conversionPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson, double-conversion
API changes (from Hackage documentation)
- Web.Google.Static.Maps: Geometry :: Element
- Web.Google.Static.Maps: Labels :: Element
- Web.Google.Static.Maps: instance GHC.Classes.Eq Web.Google.Static.Maps.Key
- Web.Google.Static.Maps: instance GHC.Classes.Eq Web.Google.Static.Maps.Location
- Web.Google.Static.Maps: instance GHC.Show.Show Web.Google.Static.Maps.Key
- Web.Google.Static.Maps: instance GHC.Show.Show Web.Google.Static.Maps.Location
- Web.Google.Static.Maps: instance Web.Internal.HttpApiData.ToHttpApiData Web.Google.Static.Maps.Key
- Web.Google.Static.Maps: instance Web.Internal.HttpApiData.ToHttpApiData Web.Google.Static.Maps.Location
- Web.Google.Static.Maps: instance Web.Internal.HttpApiData.ToHttpApiData [Web.Google.Static.Maps.Location]
+ Web.Google.Maps.Common: Key :: Text -> Key
+ Web.Google.Maps.Common: Location :: Double -> Double -> Location
+ Web.Google.Maps.Common: [lat] :: Location -> Double
+ Web.Google.Maps.Common: [lng] :: Location -> Double
+ Web.Google.Maps.Common: data Location
+ Web.Google.Maps.Common: googleMapsApis :: BaseUrl
+ Web.Google.Maps.Common: instance Data.Aeson.Types.FromJSON.FromJSON Web.Google.Maps.Common.Location
+ Web.Google.Maps.Common: instance GHC.Classes.Eq Web.Google.Maps.Common.Key
+ Web.Google.Maps.Common: instance GHC.Classes.Eq Web.Google.Maps.Common.Location
+ Web.Google.Maps.Common: instance GHC.Generics.Generic Web.Google.Maps.Common.Location
+ Web.Google.Maps.Common: instance GHC.Show.Show Web.Google.Maps.Common.Key
+ Web.Google.Maps.Common: instance GHC.Show.Show Web.Google.Maps.Common.Location
+ Web.Google.Maps.Common: instance Web.Internal.HttpApiData.ToHttpApiData Web.Google.Maps.Common.Key
+ Web.Google.Maps.Common: instance Web.Internal.HttpApiData.ToHttpApiData Web.Google.Maps.Common.Location
+ Web.Google.Maps.Common: instance Web.Internal.HttpApiData.ToHttpApiData [Web.Google.Maps.Common.Location]
+ Web.Google.Maps.Common: newtype Key
+ Web.Google.Static.Maps: AllGeometry :: Element
+ Web.Google.Static.Maps: AllLabels :: Element
Files
- changelog.md +12/−2
- google-static-maps.cabal +4/−1
- src/Web/Google/Maps/Common.hs +58/−0
- src/Web/Google/Static/Maps.hs +10/−32
changelog.md view
@@ -1,3 +1,13 @@+# 0.3.0.0 + +* Fix bug in instance of `ToHttpApiData` for `Location` + +* Rename certain constructors of `Element` type to avoid name clashes + (`Geometry` and `Labels`) + +* Move functions and types of anticipated common use to module + `Web.Google.Maps.Common` + # 0.2.0.0 * Implementation of `signature` and custom marker icons @@ -10,5 +20,5 @@ # 0.1.0.0 * Launch implementation. Not yet implemented: certain optional parameters - (language, region and signature); address locations; non-PNG image formats; - custom marker icons; and encoded polyline paths. + (`language`, `region` and `signature`); address locations; non-PNG image + formats; custom marker icons; and encoded polyline paths
google-static-maps.cabal view
@@ -1,5 +1,5 @@ name: google-static-maps-version: 0.2.0.0+version: 0.3.0.0 synopsis: Bindings to the Google Static Maps API description: The <https://developers.google.com/maps/documentation/static-maps/intro Google Static Maps API> returns a map as an image via an HTTP request. This library@@ -25,8 +25,11 @@ library hs-source-dirs: src exposed-modules: Web.Google.Static.Maps+ , Web.Google.Maps.Common build-depends: base >= 4.7 && < 5+ , aeson >= 1.0 && < 1.1 , bytedump >= 1.0 && < 1.1+ , double-conversion >= 2.0 && < 2.1 , http-client >= 0.5 && < 0.6 , JuicyPixels >= 3.2 && < 3.3 , network-uri >= 2.6 && < 2.7
+ src/Web/Google/Maps/Common.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE OverloadedStrings #-} + +-- | +-- Module : Web.Google.Maps.Common +-- Description : Bindings to the Google Static Maps API +-- Copyright : (c) Mike Pilgrem 2017 +-- Maintainer : public@pilgrem.com +-- Stability : experimental +-- +-- This module has no connection with Google Inc. or its affiliates. +module Web.Google.Maps.Common + ( -- * Functions + googleMapsApis + -- * Types + , Key (..) + , Location (..) + ) where + +import Data.Aeson (FromJSON) +import Data.Double.Conversion.Text (toFixed) +import Data.List (intersperse) +import Data.Text (Text) +import qualified Data.Text as T (concat) +import GHC.Generics (Generic) +import Servant.API (ToHttpApiData (..)) +import Servant.Client (BaseUrl (..), Scheme (..)) + +-- | API key +newtype Key = Key Text + deriving (Eq, Show, ToHttpApiData) + +-- | Location: precision in latitude or longitude beyond 6 decimal places is +-- ignored. +data Location = Location + { lat :: Double -- ^ Takes any value between -90 and 90. + , lng :: Double -- ^ Takes any value between -180 and 180. + } deriving (Eq, Show, Generic) + +instance ToHttpApiData Location where + toUrlPiece (Location lat' lng') = T.concat [toFixed precision lat', ",", + toFixed precision lng'] + where + precision = 6 -- Precision beyond 6 decimal places is ignored. + +instance ToHttpApiData [Location] where + toUrlPiece [] = "" + toUrlPiece ls = T.concat $ intersperse pipe $ map toUrlPiece ls + where + pipe = toUrlPiece ("|" :: Text) + +instance FromJSON Location + +-- | The base URL for the Google Maps APIs. +googleMapsApis :: BaseUrl +googleMapsApis = BaseUrl Https "maps.googleapis.com" 443 "/maps/api"
src/Web/Google/Static/Maps.hs view
@@ -32,8 +32,6 @@ -- > -- > module Main (main) where -- > --- > import Codec.Picture.Saving (imageToPng) -- package JuicyPixels --- > import qualified Data.ByteString.Lazy as B (writeFile) -- > import Data.Maybe (fromJust) -- > import Graphics.Gloss (Display (..), display, white) -- package gloss -- > import Graphics.Gloss.Juicy (fromDynamicImage) -- package gloss-juicy @@ -113,14 +111,12 @@ import Network.HTTP.Client (Manager) import Network.URI (URI (..), URIAuth (..), uriToString) import Servant.API ((:>), Get, QueryParam, QueryParams, ToHttpApiData (..)) -import Servant.Client (BaseUrl (..), client, ClientEnv (..), ClientM, - runClientM, Scheme (..), ServantError) +import Servant.Client (client, ClientEnv (..), ClientM, runClientM, + ServantError) import Servant.JuicyPixels (PNG) import Text.Bytedump (hexString) --- | API key -newtype Key = Key Text - deriving (Eq, Show, ToHttpApiData) +import Web.Google.Maps.Common (googleMapsApis, Key (..), Location (..)) -- | Signature newtype Signature = Signature Text @@ -130,21 +126,6 @@ newtype Center = Center Location deriving (Eq, Show, ToHttpApiData) --- | Location -data Location = Location - { lat :: Double -- ^ Takes any value between -90 and 90. - , lng :: Double -- ^ Takes any value between -180 and 180. - } deriving (Eq, Show) - -instance ToHttpApiData Location where - toUrlPiece (Location lat' lng') = T.pack (show lat' ++ "," ++ show lng') - -instance ToHttpApiData [Location] where - toUrlPiece [] = "" - toUrlPiece ls = T.concat $ intersperse pipe $ map toUrlPiece ls - where - pipe = toUrlPiece ("|" :: Text) - -- | Zoom level: the lowest level, in which the whole world can be seen, is 0. -- Each succeeding level doubles the precision. Not required if the map includes -- markers or paths. @@ -290,10 +271,10 @@ -- | Feature element data Element = AllElements - | Geometry + | AllGeometry | GeometryFill | GeometryStroke - | Labels + | AllLabels | LabelsIcon | LabelsText | LabelsTextFill @@ -303,10 +284,10 @@ instance ToHttpApiData Element where toUrlPiece element = case element of AllElements -> "all" - Geometry -> "geometry" + AllGeometry -> "geometry" GeometryFill -> "geometry.fill" GeometryStroke -> "geometry.stroke" - Labels -> "labels" + AllLabels -> "labels" LabelsIcon -> "labels.icon" LabelsText -> "labels.text" LabelsTextFill -> "labels.text.fill" @@ -467,10 +448,10 @@ deriving (Eq, Show) instance ToHttpApiData Anchor where - toUrlPiece anchor - | AnchorPoint x y <- anchor + toUrlPiece anchor' + | AnchorPoint x y <- anchor' = T.pack (show x ++ "," ++ show y) - | StdAnchor stdAnchor <- anchor + | StdAnchor stdAnchor <- anchor' = toUrlPiece stdAnchor -- | Standard anchor points @@ -598,9 +579,6 @@ -> Maybe Visible -> ClientM StaticmapResponse staticmap' = client api - -googleMapsApis :: BaseUrl -googleMapsApis = BaseUrl Https "maps.googleapis.com" 443 "/maps/api" -- | Retrieve a static map. NB: The use of the Google Static Maps API services -- is subject to the <https://developers.google.com/maps/terms Google Maps APIs Terms of Service>.