Restrict Google DistanceMatrixService to return only land routes

21 Views Asked by At

This is the code snippet for google distance matrix api (its wrapped under a promise):

const matrix = new google.maps.DistanceMatrixService();

matrix.getDistanceMatrix({
   origins: [new google.maps.LatLng(lat1,lng1)],
   destinations: [new google.maps.LatLng(lat2,lng2)],
   travelMode: google.maps.TravelMode.DRIVING,
   avoidFerries: true,
}, ( response, status ) => {
   if (status === 'OK') {
      console.log("distMatrix res",response);
      const distance = response?.rows[0]?.elements[0]?.distance?.value
      const duration = response?.rows[0]?.elements[0]?.duration.value
      resolve({distance, duration})
   } else {
      console.error('Error:', status);
      reject(response)
   }
});

I want it to return distance/duration only for those routes that have land connection. In other words, Avoid ferry, Aeroplane etc and give only car routes.

I looked on official docs and it says (see here):

Note: The addition of restrictions does not preclude routes that include the restricted feature; it biases the result to more favorable routes.

So is there any manual way (if not automatic) to check if route include only car ways (so to speak) ? So that I can restrict them to avoid boats, ferry, Flight etc

0

There are 0 best solutions below