Compute a distance/duration matrix with Thinwrap (PHP)

Compute an origins-to-destinations matrix via the Thinwrap unified Matrix 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\Matrix;
use Thinwrap\Location\Config\MapboxConfig;
use Thinwrap\Location\DTO\Matrix\MatrixOptions;
use Thinwrap\Location\DTO\LatLng;
use Thinwrap\Location\Enum\LocationProviderId;
use Thinwrap\Location\Enum\TravelMode;

$matrix = new Matrix(
    LocationProviderId::Mapbox,
    new MapboxConfig(accessToken: getenv('MAPBOX_TOKEN')),
);

$result = $matrix->matrix(new MatrixOptions(
    origins: [new LatLng(37.7749, -122.4194)],
    destinations: [
        new LatLng(37.3382, -121.8863),
        new LatLng(37.8716, -122.2727),
    ],
    travelMode: TravelMode::Driving,
));

// Flat cells[]: { originIndex, destinationIndex, distanceMeters, durationSeconds }
foreach ($result->cells as $cell) {
    echo $cell->originIndex, ' -> ', $cell->destinationIndex,
         ' ', $cell->durationSeconds, "s\n";
}

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