Geocode an address with Thinwrap (Erlang)
Resolve an address to coordinates via thinwrap_location:geocode/2 in Erlang — one call shape for Mapbox, Google, HERE and more.
1. Install
{deps, [{thinwrap_location, "~> 1.3"}]}.2. Send the call
Config = #{provider => google,
api_key => list_to_binary(os:getenv("GOOGLE_MAPS_API_KEY"))},
case thinwrap_location:geocode(Config, #{
address => <<"1600 Amphitheatre Parkway, Mountain View, CA">>,
country_filter => [<<"US">>]
}) of
{ok, #{candidates := Candidates}} ->
lists:foreach(
fun(#{formatted_address := Addr, location := #{lat := Lat, lng := Lng}}) ->
io:format("~ts ~p ~p~n", [Addr, Lat, Lng])
end, Candidates);
{error, #{code := Code, message := Msg}} ->
io:format("~s: ~ts~n", [Code, Msg])
end.
Same code works for all supported providers — just change the provider ID.