Compute an isochrone with Thinwrap (Erlang)

Compute a travel-time or travel-distance polygon via thinwrap_location:isochrone/2 in Erlang — one call shape for Mapbox, HERE, ESRI and TomTom.

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:isochrone(Config, #{
    center => #{lat => 52.5200, lng => 13.4050},
    type => time,
    values => [300, 600],  % seconds
    travel_mode => driving
}) of
    %% Each contour carries a GeoJSON Polygon (or MultiPolygon) of [lng, lat] rings.
    {ok, #{contours := Contours}} ->
        lists:foreach(
            fun(#{value := V, geometry := #{type := Type, coordinates := Rings}}) ->
                io:format("~p ~s ~B~n", [V, Type, length(Rings)])
            end, Contours);
    {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.