Compare if there is a point on a given route


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.


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() {

            //*********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) {

            //*********DISTANCIA E DURACAO**********************//
            var service = new google.maps.DistanceMatrixService();
                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.");
asked by anonymous 29.03.2017 / 16:46

1 answer


Google Maps does not provide the option to see how many tolls a route has. Unlike many Google Maps conditions, you can not tell a code within a code to calculate the amount of x locations on a specific route.

However, you can enter a condition so ALL routes it calculates avoid tolls. Simply enter avoid=tolls (Toll) in the API call link. In this case, the link will look like this:

<script src=",geometry&avoid=tolls"asyncdefer></script>


Fullresourcedocumentation this link

Ah, by increasing the response, Google allows you to avoid as well as tolls, freeways and ferries. In this case, just put one or all of the items here: avoid=tolls|highways|ferries

29.03.2017 / 19:03