I have a page that calculates the distance between Point A and Point B , but I need to compute tolls on this route.
I think of having a bank with the toll (lat and lng) coordinates and check if it exists on the route, but I do not know how.
I need to return the number of tolls and their values in the Point A - Point B range. Any help will be valid.
JavaScript:
var options = {
componentRestrictions: {country: 'br'}
};
var source, destination;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
google.maps.event.addDomListener(window, 'load', function () {
new google.maps.places.Autocomplete(document.getElementById('txtSource'), options);
new google.maps.places.Autocomplete(document.getElementById('txtDestination'), options);
directionsDisplay = new google.maps.DirectionsRenderer({ 'draggable': true });
});
var mumbai = new google.maps.LatLng(-19.9166813, -43.9344931);
var mapOptions = {
zoom: 5,
center: mumbai
};
map = new google.maps.Map(document.getElementById('dvMap'), mapOptions);
function GetRoute() {
directionsDisplay.setMap(map);
//directionsDisplay.setPanel(document.getElementById('dvPanel'));
//*********DIRECOES E ROTAS**********************//
source = document.getElementById("txtSource").value;
destination = document.getElementById("txtDestination").value;
var request = {
origin: source,
destination: destination,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
//*********DISTANCIA E DURACAO**********************//
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({
origins: [source],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
},
function (response, status) {
if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status != "ZERO_RESULTS") {
var distance = response.rows[0].elements[0].distance.text;
var duration = response.rows[0].elements[0].duration.text;
var dvDistance = document.getElementById("dvDistance");
dvDistance.innerHTML = "";
dvDistance.innerHTML += "Distancia: " + distance + "<br />";
dvDistance.innerHTML += "Duração:" + duration + "<br />";
} else {
alert("Não foi possível traçar essa rota.");
}
});
}