Compute a distance/duration matrix with Thinwrap (TypeScript)
Compute an origins-to-destinations matrix via the Thinwrap unified Matrix facade in TypeScript — same call shape for Mapbox, Google, HERE, ESRI, TomTom, and OSRM.
1. Install
npm install @thinwrap/location2. Send the call
import { Matrix } from '@thinwrap/location';
const matrix = new Matrix('mapbox', {
accessToken: process.env.MAPBOX_TOKEN!,
});
const result = await matrix.matrix({
origins: [
{ lat: 37.7749, lng: -122.4194 }, // San Francisco
],
destinations: [
{ lat: 37.3382, lng: -121.8863 }, // San Jose
{ lat: 37.8716, lng: -122.2727 }, // Berkeley
],
travelMode: 'driving',
});
// Flat cells[]: { originIndex, destinationIndex, distanceMeters, durationSeconds }
for (const cell of result.cells) {
console.log(cell.originIndex, '→', cell.destinationIndex, cell.durationSeconds, 's');
}
Same code works for all supported providers — just change the provider ID.