I am getting trouble while getting the Shortest route . The Problem is that there is difference between the distance shown in google map and shortest routes get by the google.maps.DirectionsService(); I am also getting alternative roues but that still not match with distance show on map .. enter image description here
The Distance shown in Map is 15-km but the shortest routes by google.maps.DirectionsService() is 18.3-Km I want to get the distance shown in map as in image i attach. code...
directionsService.route(request, function(response, status) {
if (status === 'OK') {
let route_options = [];
for (var i = 0; i < response.routes.length; i++)
{
let route = response.routes[i];
let distance = 0;
// Total the legs to find the overall journey distance for each route option
for (var j = 0; j < route.legs.length; j++)
{
distance += route.legs[j].distance.value; // metres
}
route_options.push({
'route_id': i,
'distance': distance
});
}
route_options.sort(function(a, b) {
return parseInt(a.distance) - parseInt(b.distance);
});
let duration = response.routes[0].legs[0].duration.value;
let shortest_distance = (route_options[0]['distance'] * 0.001); // convert metres to kilometres
return shortest_distance;
}
});
}