Compute a route with Thinwrap (Elixir)

Compute a route via :thinwrap_location.route/2 in Elixir — one call shape for Mapbox, Google, HERE, ESRI, TomTom and OSRM.

1. Install

{:thinwrap_location, "~> 1.3"}

2. Send the call

config = %{provider: :mapbox, access_token: System.fetch_env!("MAPBOX_ACCESS_TOKEN")}

case :thinwrap_location.route(config, %{
       waypoints: [%{lat: 52.5200, lng: 13.4050}, %{lat: 52.5163, lng: 13.3777}],
       travel_mode: :driving
     }) do
  # polyline is the encoded geometry; raw keeps the vendor body verbatim.
  {:ok, %{total_distance_meters: meters, total_duration_seconds: seconds}} ->
    IO.puts("#{meters} #{seconds}")

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

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