22 lines
1.1 KiB
JavaScript
22 lines
1.1 KiB
JavaScript
const axios = require('axios');
|
|
require('dotenv').config({ path: '.env' });
|
|
|
|
async function testSteps() {
|
|
const apiKey = process.env.API_MAPS;
|
|
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
|
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
|
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
|
destination: { address: "Toulouse, France" },
|
|
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.legs.steps.navigationInstruction,routes.legs.steps.distanceMeters,routes.legs.steps.startLocation,routes.legs.steps.endLocation' } });
|
|
|
|
const steps = resToll.data.routes[0].legs[0].steps;
|
|
for(let i=0; i<steps.length; i++) {
|
|
const step = steps[i];
|
|
const inst = step.navigationInstruction ? step.navigationInstruction.instructions : '';
|
|
if(inst.toLowerCase().includes('péage') || inst.toLowerCase().includes('toll')) {
|
|
console.log(`Step ${i}: ${inst} (Dist: ${step.distanceMeters}m)`);
|
|
}
|
|
}
|
|
}
|
|
testSteps();
|