fabiommendes / elm-latlng / LatLng

Location objects

This module provides a basic data structure to represent locations as a pair of latitude/longitude variables.

Types


type LatLng

A Point with latitude/longitude coordinates


type alias Coord =
{ sign : Basics.Int
, deg : Basics.Int
, min : Basics.Int
, sec : Basics.Int
, ms : Basics.Int 
}

Split coordinate component parts Sign is either -1 or 1 and all other components are positive


type alias Polyline =
List LatLng

A list of LatLng points


type alias Path =
List ( Length
, Length 
}

A list of (x, y) coordinates


type alias Angle =
Angle

Re-expose Angle from elm-units


type alias Length =
Length

Re-expose Length from elm-units

Creation

fromLatLng : Angle -> Angle -> LatLng

Create location from lat/lng values

fromLatLngDegrees : Basics.Float -> Basics.Float -> LatLng

Create location from lat/lng values

Parsing and rendering

parse : String -> Maybe LatLng

Parse a pretty string of Lat/Lon data

parsePair : String -> Maybe LatLng

Convert string with a pair of floats to a LatLng pair

parseCoord : ( String, String ) -> String -> Maybe Coord

Parse a single coordinate with the given pair of directions

This can be used to specify the N-S or E-W directions or localized versions of those symbols

Example parseCoord ("L", "O") "45°10'50.12L" ==> Coord 1 45 10 50 120

toString : LatLng -> String

Render lat/lng as a pretty printed string

coordToString : Angle -> String -> String -> String

Format a decimal latitude or longitude coordinate

coordToString -45.5 "N" "S" ==> "45°30'00.00\"S"

googleMapsUrl : LatLng -> String

Google Maps URL associated with the given location

Properties and comparison

latitude : LatLng -> Angle

Return location`s latitude

longitude : LatLng -> Angle

Return location`s longitude

coord : Angle -> Coord

Extract coordinate parts from float

distance : LatLng -> LatLng -> Length

Distance between two points, in meters.

Uses the great circle distance (https://en.wikipedia.org/wiki/Great-circle_distance)

This approximates the Earth by a sphere, which in most occasions is good enough.

toAngle : Coord -> Angle

Converts Coord to float

toTupleDegrees : LatLng -> ( Basics.Float, Basics.Float )

Convert LatLng to a tuple of floats

Moving points around

We can move points specifying variations in lat/lon Angles, Meters or in Coords

By angle

by : Angle -> Angle -> LatLng -> LatLng

Move location by given lat and lng angles

eastBy : Angle -> LatLng -> LatLng

Move point east by given longitude angle

westBy : Angle -> LatLng -> LatLng

Move point west by given longitude angle

northBy : Angle -> LatLng -> LatLng

Move point north by given latitude angle

southBy : Angle -> LatLng -> LatLng

Move point south by given latitude angle

By length

move : Length -> Length -> LatLng -> LatLng

Move point by (x, y) distance

moveEast : Length -> LatLng -> LatLng

Move point east by given distance

moveWest : Length -> LatLng -> LatLng

Move point west by given distance

moveNorth : Length -> LatLng -> LatLng

Move point north by given distance

moveSouth : Length -> LatLng -> LatLng

Move point south by given distance

By coord

eastByCoords : Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> LatLng -> LatLng

Move point east by given longitude cooordinates (in degrees, minutes, seconds, milliseconds)

westByCoords : Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> LatLng -> LatLng

Move point west by given longitude cooordinates (in degrees, minutes, seconds, milliseconds)

northByCoords : Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> LatLng -> LatLng

Move point south by given latitude cooordinates (in degrees, minutes, seconds, milliseconds)

southByCoords : Basics.Int -> Basics.Int -> Basics.Int -> Basics.Int -> LatLng -> LatLng

Move point south by given latitude cooordinates (in degrees, minutes, seconds, milliseconds)

Paths and Polylines

center : Polyline -> LatLng

Computes the center point of the polyline

chain : LatLng -> List (LatLng -> LatLng) -> List LatLng

Make a chain of transformations in the given point

Each transformation is typically an operation like moveNorth (meters 5)

Return a list of partial applications.

Example:

chain loc
    [ move (meters 60) (meters 10)
    , northByCoords 0 0 1 256
    , westBy (Angle.degrees 180)
    ]

pathFrom : LatLng -> Polyline -> Path

Create linear path starting at the given LatLng point

The conversion assumes the earth is locally flat, i.e., it gives good results for nearby points and poor conversions if distances are comensuarable to Earth radius.

pathFromCenter : Polyline -> Path

Convert Polyline into path, taking the center point as the origin.

pathFromStart : Polyline -> Path

Convert Polyline into path

Works like pathFrom, but uses the first element of list as the origin reference

Encoding/Decoding

encoder : LatLng -> Json.Encode.Value

Encode LatLng as a JSON string

decoder : Json.Decode.Decoder LatLng

Decode LatLng from a known format

decodePair : Json.Decode.Decoder LatLng

Decode location from a string with a pair of floats

decodePretty : Json.Decode.Decoder LatLng

Decode LatLng from a prettified representation in a JSON string

decodeTuple : Json.Decode.Decoder LatLng

Decode location from a string with a pair of floats