Guest User

Untitled

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. module Data.Coordinates exposing (..)
  2.  
  3. import Json.Decode as Decode exposing (Decoder, float, Value)
  4. import Json.Encode as Encode
  5. import Json.Decode.Pipeline as Pipeline exposing (required)
  6. import Geolocation
  7.  
  8. type alias Coordinates =
  9. { latitude : Float
  10. , longitude : Float
  11. }
  12.  
  13. decode : Decoder Coordinates
  14. decode =
  15. Pipeline.decode Coordinates
  16. |> required "latitude" float
  17. |> required "longitude" float
  18.  
  19. encode : Coordinates -> Value
  20. encode coordinates =
  21. Encode.object
  22. [ ("latitude", Encode.float coordinates.latitude)
  23. , ("longitude", Encode.float coordinates.longitude)
  24. ]
  25.  
  26. fromGeolocation : Geolocation.Location -> Coordinates
  27. fromGeolocation loc =
  28. Coordinates loc.latitude loc.longitude
Add Comment
Please, Sign In to add comment