URL.Geo (URL v2.0.3)

Copy Markdown View Source

Parses the scheme-specific part of a geo URL as defined in RFC 5870.

A geo URL carries a latitude, a longitude, an optional altitude and optional parameters such as crs and u. The primary API is parse/1, which URL.new/1 calls for any URL with the geo scheme.

Summary

Functions

Parses the path of a geo URI into a t/0 struct.

Types

t()

@type t() :: %URL.Geo{
  alt: nil | number(),
  lat: number(),
  lng: number(),
  params: map()
}

Functions

parse(uri)

@spec parse(URI.t()) :: {:ok, t()} | {:error, {module(), binary()}}

Parses the path of a geo URI into a t/0 struct.

Arguments

  • uri is a URI.t/0 whose :scheme is "geo".

Returns

  • {:ok, t:t/0} with the latitude, longitude, altitude (nil when absent) and parameters. The u (uncertainty) parameter is converted to a number, or

  • {:error, {URL.Parser.ParseError, reason}} if the path is not a valid geo payload, including an empty path.

Examples

iex> geo = URI.parse("geo:48.198634,-16.371648,3.4;crs=wgs84;u=40.0")
iex> URL.Geo.parse(geo)
{:ok,
 %URL.Geo{
   lat: 48.198634,
   lng: -16.371648,
   alt: 3.4,
   params: %{"crs" => "wgs84", "u" => 40.0}
 }}

iex> URL.Geo.parse(URI.parse("geo:48.198634,-16.371648"))
{:ok, %URL.Geo{lat: 48.198634, lng: -16.371648, alt: nil, params: %{}}}

iex> {:error, {URL.Parser.ParseError, _reason}} = URL.Geo.parse(URI.parse("geo:48.198634"))