LibLatLon v0.4.1 LibLatLon.Coords View Source

Main struct to be used as coordinates representation.

One might cast nearly everything to LibLatLon.Coord with LibLatLon.Coord.borrow/1 and/or LibLatLon.Coord.borrow/2.

This struct implements both String.Chars and Inspect protocols. The fancy string representation of any lat/lon pair might be get by Kernel.to_string/1:

iex> to_string(LibLatLon.Coords.borrow(lat: 41.38, lon: 2.19))
"41°22´48.0˝N,2°11´24.0˝E"

Note, that this representation might be used as is when querying any geolocation services and/or GoogleMaps. Try:

  • http://maps.google.com?search=41°22´48.0˝N,2°11´24.0˝E

Link to this section Summary

Types

Degrees, minutes and seconds as a tuple

Degrees, minutes and seconds as a list

Degrees, minutes and seconds with an optional semisphere reference

t()

The type to store coordinates

Functions

Converts literally any input to LibLatLon.Coords instance

Converts {{degree, minute, second}, semisphere} or {[degree, minute, second], semisphere} representation into LibLatLon.Coords

Converts degree, minute, second, semisphere representation into LibLatLon.Coords. When the last parameter semisphere is not one of: "S" or "W" or -1 or :south or west, it is implicitly considered to be in NE semisphere

Retrieves coordinates from barely anything

Converts literally anything, provided as combined latlon value to two tuples {{degree, minute, second}, semisphere}. Barely used from the outside the package, since LibLatLon.Coords.t is obviously better type to work with coordinates by all means

Converts literally anything, provided as latitude and longitude values to two tuples {{degree, minute, second}, semisphere}. Barely used from the outside the package, since LibLatLon.Coords.t is obviously better type to work with coordinates by all means

Link to this section Types

Link to this type dms() View Source
dms() :: {number(), number(), number()}

Degrees, minutes and seconds as a tuple

Link to this type dms_list() View Source
dms_list() :: [number()]

Degrees, minutes and seconds as a list

Link to this type dms_ss() View Source
dms_ss() :: {dms() | dms_list(), binary() | nil}

Degrees, minutes and seconds with an optional semisphere reference

Link to this type t() View Source
t() :: %LibLatLon.Coords{alt: number(), direction: number(), lat: number(), lon: number(), magnetic?: true | false}

The type to store coordinates.

Mostly used fields are lat and lon, stored as Float.t. Also might contain altitude and direction to calculate the latitude and langitude for the destination point (mostly used when dealing with EXIF information from images.)

Link to this section Functions

Link to this function borrow(lat_or_lon) View Source
borrow({number(), number()} | nil | {dms_ss(), dms_ss()} | dms_ss() | [number()] | map() | binary() | Keyword.t() | Exexif.Data.Gps.t({} | number())) ::
  LibLatLon.Coords.t() |
  number() |
  nil |
  {:error, any()}

Converts literally any input to LibLatLon.Coords instance.

Examples

iex> LibLatLon.Coords.borrow("41°23´16˝N,2°11´50˝E")
%LibLatLon.Coords{lat: 41.38777777777778, lon: 2.197222222222222}

iex> LibLatLon.Coords.borrow("41°23´16.222˝N,2°11´50.333˝E")
%LibLatLon.Coords{lat: 41.387839444444445, lon: 2.197314722222222}

iex> LibLatLon.Coords.borrow({{{41, 23, 16.0}, "N"}, {{2, 11, 50.0}, "E"}})
%LibLatLon.Coords{lat: 41.38777777777778, lon: 2.197222222222222}

iex> LibLatLon.Coords.borrow(lat: 41.38, lon: 2.19)
%LibLatLon.Coords{lat: 41.38, lon: 2.19}
Link to this function borrow(arg1, ss) View Source
borrow(dms(), any()) :: number()
borrow(dms_list(), any()) :: number()

Converts {{degree, minute, second}, semisphere} or {[degree, minute, second], semisphere} representation into LibLatLon.Coords.

Link to this function borrow(d, m, s, ss \\ nil) View Source
borrow(number(), number(), number(), any()) :: number()

Converts degree, minute, second, semisphere representation into LibLatLon.Coords. When the last parameter semisphere is not one of: "S" or "W" or -1 or :south or west, it is implicitly considered to be in NE semisphere.

Link to this function coordinate(buffer) View Source
coordinate(nil | binary() | %{} | any()) ::
  {:ok, LibLatLon.Coords.t()} |
  {:error, any()}

Retrieves coordinates from barely anything.

iex> {:ok, result} = LibLatLon.Coords.coordinate("test/inputs/1.jpg")
...> result
#Coord<[lat: 41.37600333333334, lon: 2.1486783333333332, fancy: "41°22´33.612˝N,2°8´55.242˝E"]>

iex> LibLatLon.Coords.coordinate("test/inputs/unknown.jpg")
{:error, {:weird_input, [nil]}}
Link to this function coordinate!(whatever) View Source
coordinate!(nil | binary() | %{} | any()) ::
  LibLatLon.Coords.t() |
  no_return()

Same as LibLatLon.Coords.coordinate/1, but banged.

Examples

iex> LibLatLon.Coords.coordinate!("test/inputs/1.jpg")
#Coord<[lat: 41.37600333333334, lon: 2.1486783333333332, fancy: "41°22´33.612˝N,2°8´55.242˝E"]>
Link to this function lend(arg1) View Source
lend({number(), number()} | [number()] | LibLatLon.Coords.t()) :: {dms_ss(), dms_ss()}

Converts literally anything, provided as combined latlon value to two tuples {{degree, minute, second}, semisphere}. Barely used from the outside the package, since LibLatLon.Coords.t is obviously better type to work with coordinates by all means.

Examples

iex> LibLatLon.Coords.lend({41.38777777777778, 2.197222222222222})
{{{41, 23, 16.0}, "N"}, {{2, 11, 50.0}, "E"}}

iex> LibLatLon.Coords.lend([41.38777777777778, 2.197222222222222])
{{{41, 23, 16.0}, "N"}, {{2, 11, 50.0}, "E"}}
Link to this function lend(dms1, dms2) View Source
lend(number(), number()) :: {dms_ss(), dms_ss()}

Converts literally anything, provided as latitude and longitude values to two tuples {{degree, minute, second}, semisphere}. Barely used from the outside the package, since LibLatLon.Coords.t is obviously better type to work with coordinates by all means.

Examples

iex> LibLatLon.Coords.lend(41.38777777777778, 2.197222222222222)
{{{41, 23, 16.0}, "N"}, {{2, 11, 50.0}, "E"}}