Compute a distance matrix (Erlang)
Compute an origins-to-destinations matrix via thinwrap_location:matrix/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"))},
%% Providers bill per origin x destination pair — keep probe matrices small.
case thinwrap_location:matrix(Config, #{
origins => [#{lat => 52.5200, lng => 13.4050}],
destinations => [#{lat => 52.5163, lng => 13.3777},
#{lat => 52.5096, lng => 13.3765}],
travel_mode => driving
}) of
{ok, #{cells := Cells}} ->
lists:foreach(
fun(#{origin_index := O, destination_index := D,
distance_meters := M, duration_seconds := S}) ->
io:format("~B ~B ~p ~p~n", [O, D, M, S])
end, Cells);
{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.