Compute a route with Thinwrap (Erlang)

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

1. Install

{deps, [{thinwrap_location, "~> 1.3"}]}.

2. Send the call

Config = #{provider => mapbox,
           access_token => list_to_binary(os:getenv("MAPBOX_ACCESS_TOKEN"))},

case thinwrap_location:route(Config, #{
    waypoints => [#{lat => 52.5200, lng => 13.4050},
                  #{lat => 52.5163, lng => 13.3777}],
    travel_mode => driving
}) of
    %% polyline is the encoded geometry; raw keeps the vendor body verbatim.
    {ok, #{total_distance_meters := Meters, total_duration_seconds := Seconds}} ->
        io:format("~p ~p~n", [Meters, Seconds]);
    {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.