Pluscode
View SourceAn Elixir implementation of Open Location Code (Plus Codes), a technology developed by Google that encodes location into a short, easy to share code. For more information, visit plus.codes.
Features
- Encode latitude/longitude to Plus Codes
- Decode Plus Codes to coordinates
- Validate Plus Codes
- Shorten codes relative to a reference location
- Recover full codes from shortened versions
- Full compatibility with the official specification
Installation
If available in Hex, the package can be installed
by adding pluscode
to your list of dependencies in mix.exs
:
def deps do
[
{:pluscode, "~> 0.1.0"}
]
end
Usage
# Encode a location
iex> Pluscode.encode(47.365590, 8.524997)
"8FVC9G8F+6X"
# Encode with higher precision
iex> Pluscode.encode(47.365590, 8.524997, 11)
"8FVC9G8F+6XQ"
# Decode a code
iex> area = Pluscode.decode("8FVC9G8F+6X")
iex> {area.latitude_center, area.longitude_center}
{47.365625, 8.525}
# Validate a code
iex> Pluscode.valid?("8FVC9G8F+6X")
true
# Shorten a code (using a reference location)
iex> Pluscode.shorten("8FVC9G8F+6X", 47.5, 8.5)
"9G8F+6X"
# Recover a full code from a short code
iex> Pluscode.recover_nearest("9G8F+6X", 47.4, 8.6)
"8FVC9G8F+6X"
Documentation
Detailed documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/pluscode.
License
This implementation is licensed under the Apache License, Version 2.0. See the LICENSE file for details.