PlusCodes v1.0.0 PlusCodes.OpenLocationCode View Source

Implements the Google Open Location Code(Plus+Codes) algorithm.

Link to this section Summary

Functions

Decodes an Open Location Code(Plus+Codes) into a PlusCodes.CodeArea struct. Returns an :ok/:error tuple

Decodes an Open Location Code(Plus+Codes) into a PlusCodes.CodeArea struct. Raises an exception on argument error

Converts a latitude and longitude into a Open Location Code(Plus+Codes). Returns an :ok/:error tuple

Converts a latitude and longitude into a Open Location Code(Plus+Codes). Raises an exception on argument error

Determines if a string is a valid full Open Location Code(Plus+Codes)

Recovers a full Open Location Code(Plus+Codes) from a short code and a reference location. Returns an :ok/:error tuple

Recovers a full Open Location Code(Plus+Codes) from a short code and a reference location. Raises an exception on argument error

Determines if a string is a valid short Open Location Code(Plus+Codes)

Removes four, six or eight digits from the front of an Open Location Code(Plus+Codes) given a reference location. Returns an :ok/:error tuple

Removes four, six or eight digits from the front of an Open Location Code(Plus+Codes) given a reference location. Raises an exception on argument error

Determines if a string is a valid sequence of Open Location Code(Plus+Codes) characters

Link to this section Functions

Link to this function decode(code) View Source
decode(String.t()) :: {:ok, PlusCodes.CodeArea.t()} | {:error, String.t()}

Decodes an Open Location Code(Plus+Codes) into a PlusCodes.CodeArea struct. Returns an :ok/:error tuple

Decodes an Open Location Code(Plus+Codes) into a PlusCodes.CodeArea struct. Raises an exception on argument error.

Link to this function encode(latitude, longitude, code_length \\ 10) View Source
encode(float(), float(), integer()) :: {:ok, String.t()} | {:error, String.t()}

Converts a latitude and longitude into a Open Location Code(Plus+Codes). Returns an :ok/:error tuple

Examples

iex> PlusCodes.OpenLocationCode.encode(33.978938, -118.393812)
{:ok, "8553XJH4+HF"}
Link to this function encode!(latitude, longitude, code_length \\ 10) View Source
encode!(float(), float(), integer()) :: String.t()

Converts a latitude and longitude into a Open Location Code(Plus+Codes). Raises an exception on argument error.

Examples

iex> PlusCodes.OpenLocationCode.encode!(33.978938, -118.393812)
"8553XJH4+HF"

Determines if a string is a valid full Open Location Code(Plus+Codes).

Examples

iex> PlusCodes.OpenLocationCode.full?("8553XJH4+HF")
true

iex> PlusCodes.OpenLocationCode.full?("XJH4+HF")
false
Link to this function recover_nearest(short_code, ref_latitude, ref_longitude) View Source
recover_nearest(String.t(), float(), float()) ::
  {:ok, String.t()} | {:error, String.t()}

Recovers a full Open Location Code(Plus+Codes) from a short code and a reference location. Returns an :ok/:error tuple

Examples

iex> PlusCodes.OpenLocationCode.recover_nearest("XJH4+HF", 33.978938, -118.393812)
{:ok, "8553XJH4+HF"}
Link to this function recover_nearest!(short_code, ref_latitude, ref_longitude) View Source
recover_nearest!(String.t(), float(), float()) :: String.t()

Recovers a full Open Location Code(Plus+Codes) from a short code and a reference location. Raises an exception on argument error.

Examples

iex> PlusCodes.OpenLocationCode.recover_nearest!("XJH4+HF", 33.978938, -118.393812)
"8553XJH4+HF"

Determines if a string is a valid short Open Location Code(Plus+Codes).

Examples

iex> PlusCodes.OpenLocationCode.short?("XJH4+HF")
true

iex> PlusCodes.OpenLocationCode.short?("8553XJH4+HF")
false
Link to this function shorten(code, ref_latitude, ref_longitude) View Source
shorten(String.t(), float(), float()) ::
  {:ok, String.t()} | {:error, String.t()}

Removes four, six or eight digits from the front of an Open Location Code(Plus+Codes) given a reference location. Returns an :ok/:error tuple

Examples

iex> PlusCodes.OpenLocationCode.shorten("8553XJH4+HF", 33.978938, -118.393812)
{:ok, "+HF"}

iex> PlusCodes.OpenLocationCode.shorten("8553XJH4+HF", 33.978, -118.393)
{:ok, "H4+HF"}

iex> PlusCodes.OpenLocationCode.shorten("8553XJH4+HF", 33.9, -118.3)
{:ok, "XJH4+HF"}
Link to this function shorten!(code, ref_latitude, ref_longitude) View Source
shorten!(String.t(), float(), float()) :: String.t()

Removes four, six or eight digits from the front of an Open Location Code(Plus+Codes) given a reference location. Raises an exception on argument error.

Examples

iex> PlusCodes.OpenLocationCode.shorten!("8553XJH4+HF", 33.978938, -118.393812)
"+HF"

iex> PlusCodes.OpenLocationCode.shorten!("8553XJH4+HF", 33.978, -118.393)
"H4+HF"

iex> PlusCodes.OpenLocationCode.shorten!("8553XJH4+HF", 33.9, -118.3)
"XJH4+HF"

Determines if a string is a valid sequence of Open Location Code(Plus+Codes) characters.

Examples

iex> PlusCodes.OpenLocationCode.valid?("8553XJH4+HF")
true

iex> PlusCodes.OpenLocationCode.valid?("Not a valid code")
false
Link to this macro valid_code_length?(value) View Source (macro)