Awesome
LibLatLon
is a handy library for managing geo coordinates, that includes direct/reverse geocoding features
Installation
# config/config.exs
# Use PragDave’s exexif (default)
config :lib_lat_lon, :exexif, :exexif
# Use AM’s exexif
config :lib_lat_lon, :exexif, :nextexif
# mix.exs
def deps do
[
{:lib_lat_lon, "~> 0.8"}
]
end
Usage
Reverse lookup
LibLatLon.lookup {41.38777777777778, 2.197222222222222}
%LibLatLon.Info{
address: "Avinguda del Litoral, [...] España",
bounds: %LibLatLon.Bounds{
from: #Coord<[
lat: 41.3876663,
lon: 2.196602,
fancy: "41°23´15.59868˝N,2°11´47.7672˝E"
]>,
to: #Coord<[
lat: 41.3917431,
lon: 2.2031084,
fancy: "41°23´30.27516˝N,2°12´11.19024˝E"
]>
},
coords: #Coord<[
lat: 41.3899932,
lon: 2.2000054,
fancy: "41°23´23.97552˝N,2°12´0.01944˝E"
]>,
details: %{
city: "Barcelona",
city_district: "Sant Martí",
country: "España",
country_code: "es",
county: "BCN",
postcode: "08020",
road: "Avinguda del Litoral",
state: "CAT",
suburb: "la Vila Olímpica del Poblenou"
},
meta: %{
licence: "Data © OpenStreetMap [...]",
osm_id: "47123759",
osm_type: "way",
place_id: "82181109"
}
}
Direct lookup, using GoogleMaps
LibLatLon.lookup(
"Av. del Litoral, 28, 08005 Barcelona, Spain",
LibLatLon.Providers.GoogleMaps)
%LibLatLon.Info{
address: "Av. del Litoral, 28, 08005 Barcelona, Spain",
bounds: %LibLatLon.Bounds{
from: #Coord<[
lat: 41.3893258802915,
lon: 2.198497180291502,
fancy: "41°23´21.57316905˝N,2°11´54.58984905˝E"
]>,
to: #Coord<[
lat: 41.3866279197085,
lon: 2.195799219708499,
fancy: "41°23´11.86051095˝N,2°11´44.87719095˝E"
]>
},
coords: #Coord<[
lat: 41.3879769,
lon: 2.1971482,
fancy: "41°23´16.71684˝N,2°11´49.73352˝E"
]>,
details: %{
administrative_area_level_1: "Catalunya",
administrative_area_level_2: "Barcelona",
country: "Spain",
locality: "Barcelona",
postal_code: "08005",
route: "Avinguda del Litoral",
street_number: "28"
},
meta: %{place_id: "ChIJB801WA6jpBIRLvQ6BHMtKB4", types: ["street_address"]}
}
Currently supported providers
Currently supported sources
- latitude/longitude pair in any form (e.g.
{lat, lon}
tuple); - an address as a
binary()
; - a
jpeg
image withgps
information.
Notes about GoogleMaps
To use LibLatLon.Providers.GoogleMaps
provider, go
get API key
from Google and put the following lines into your config.exs
file:
config :lib_lat_lon, :provider, LibLatLon.Providers.GoogleMaps
config :lib_lat_lon, :google_maps_api_key, "YOUR_GOOGLE_API_KEY"
or, alternatively, use the system environment variable GOOGLE_MAPS_API_KEY
.
Docs / Changelog
0.8.0
— aggressive choice of:exexif
/:nextexif
through config (sinceCode.ensure_compiled!/1
works weird)0.7.1
— preserve defaults when options are given [credits @nathan-louie]0.7.0
— use runtime config0.6.0
— the dependencyexexif
is not expected to be specified in the main applicationmix.exs
file, use either{:exexif, "~> 0.0"}
or{:nextexif, "~> 0.0"}
; if neither is specified, the compilation error is raised
Documentation can be found at https://hexdocs.pm/lib_lat_lon.