Geocode an address with Thinwrap (Elixir)

Resolve an address to coordinates via :thinwrap_location.geocode/2 in Elixir — one call shape for Mapbox, Google, HERE and more.

1. Install

{:thinwrap_location, "~> 1.3"}

2. Send the call

config = %{provider: :google, api_key: System.fetch_env!("GOOGLE_MAPS_API_KEY")}

case :thinwrap_location.geocode(config, %{
       address: "1600 Amphitheatre Parkway, Mountain View, CA",
       country_filter: ["US"]
     }) do
  {:ok, %{candidates: candidates}} ->
    for c <- candidates do
      IO.puts("#{c.formatted_address} #{c.location.lat} #{c.location.lng}")
    end

  {:error, %{code: code, message: message}} ->
    IO.puts("#{code}: #{message}")
end

Same code works for all supported providers — just change the provider ID.