Compute a route with Thinwrap (PHP)

Compute a multi-waypoint route via the Thinwrap unified Routing facade in PHP — same call shape for Mapbox, Google, HERE, ESRI, TomTom, and OSRM.

1. Install

composer require thinwrap/location

2. Send the call

use Thinwrap\Location\Routing;
use Thinwrap\Location\Config\MapboxConfig;
use Thinwrap\Location\DTO\Routing\RoutingOptions;
use Thinwrap\Location\DTO\LatLng;
use Thinwrap\Location\Enum\LocationProviderId;
use Thinwrap\Location\Enum\TravelMode;

$routing = new Routing(
    LocationProviderId::Mapbox,
    new MapboxConfig(accessToken: getenv('MAPBOX_TOKEN')),
);

$result = $routing->route(new RoutingOptions(
    waypoints: [
        new LatLng(37.7749, -122.4194), // San Francisco
        new LatLng(37.3382, -121.8863), // San Jose
    ],
    travelMode: TravelMode::Driving,
));

// Distances normalized to meters, durations to seconds.
echo $result->totalDistanceMeters, ' / ', $result->totalDurationSeconds, PHP_EOL;
echo 'polyline: ', $result->polyline, PHP_EOL;

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