I'm trying to display multiple routes using the google maps API. But when trying with more than 10 routes I get an OVER_QUERY_LIMIT exception.
Using google, I found out, that I need to call DirectionsDisplay asynchronously using the callback function (couldn't get this to work yet). And that I have to use some sort of timeout because you can't make more than 10 requests per second.
Heres what I got so far.
<!DOCTYPE html>
<html>
<head>
    <title>Display multiple routes</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=ENTER_API_KEY"></script>
    <style>
        /* Always set the map height explicitly to define the size of the div
        * element that contains the map. */
        #map {
            height: 100%;
        }
        /* Optional: Makes the sample page fill the window. */
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        var addresses =
            [
                ['243, Dornacherstrasse', '26, Mattenstrasse'],
                ['48 av general de gaulle, saint louis', 'Gründenstraße 40, Muttenz'],
                ['50 ackerstrasse , Basel', 'holeestrasse 133, Basel'],
                ['71 avenue de Bâle , Saint-Louis ', 'Leonhardstr 6, Basel'],
                ['Ackerstrasse 44, Basel', 'Petersplatz 1, Basel'],
                ['Ackerstrasse 51, Basel', 'Maiengasse 51, Basel '],
                ['Aeussere Baselstr. 255, Riehen', 'zu den drei Linden 80, Basel'],
                ['Aeussere Baselstrasse 309, Riehen', 'Gotthelfplatz 1, Basel'],
                ['Ahornstrasse 20, Basel', 'Viaduktstrasse , Basel'],
                ['Albert Schweitzer Strasse 10, Basel', 'Kohlenberg 17, Basel'],
                ['alemannengasse 17, Basel', 'Centrahlbahnplatz, Basel'],
                ['Alemannengasse 23, Basel', 'Peter Merian-Weg 8, Basel'],
                ['Allmendstrasse 233, Basel', 'Universitätsspital Basel, Basel '],
                ['Allmendstrasse 4, Basel', 'Petersplatz 1, Basel'],
                ['Allschwilerstrasse 106, Basel', 'Centralbahnstrasse 10 , Basel'],
                ['Allschwilerstrasse 116, Basel', 'Spitalstrasse 8, Architektur Institut, Basel '],
                ['Allschwilerstrasse 116, Basel', 'Steinenvorstadt 55, Kino Pathè Küchlin, Basel'],
                ['Allschwilerstrasse 48, Basel', 'Schneidergasse 28, Basel'],
                ['Altrheinweg 52, Basel', 'Vogesenplatz 1, Basel '],
                ['Am Rheinpark 6, Weil am Rhein', 'J. J. Balmer-Str. 3, Basel'],
                ['Am Weiher 15, Binningen', 'Klingelbergstrasse 82, Basel '],
                ['Amerbachstrasse, , Basel', 'Peter Merian-Weg, Basel'],
                ['Amerikanerstrasse 16, Binningen', 'Petersplatz 1, Basel'],
                ['Amselweg 20, Reinach', 'Baselstrasse 33, Münchenstein'],
                ['An der Auhalde 15, Riehen', 'Zu den Dreilinden 95, Basel'],
                ['arnikastr. 22, Riehen', 'marktplatz, Basel'],
                ['Auf der Lyss 14, Basel', 'Grenzstrasse 15, Basel']
            ];
        var directionsDisplay;
        var directionsService = new google.maps.DirectionsService();
        var map;
        function initialize() {
            directionsDisplay = new google.maps.DirectionsRenderer();
            var basel = new google.maps.LatLng(41.850033, -87.6500523);
            var mapOptions = {
                zoom: 7,
                center: basel
            }
            map = new google.maps.Map(document.getElementById('map'), mapOptions);
            directionsDisplay.setMap(map);
        }
        function calcRoute(start, end) {
            var request = {
                origin: start,
                destination: end,
                travelMode: 'BICYCLING'
            };
            directionsService.route(request,
                function(result, status) {
                    if (status == 'OK') {
                        directionsDisplay = new google.maps.DirectionsRenderer({
                            suppressBicyclingLayer: true,
                            suppressMarkers: true
                        });
                        directionsDisplay.setMap(map);
                        directionsDisplay.setDirections(result);
                    }
                });
        }
        initialize();
        addresses.forEach(function (v, i) {
            setTimeout(calcRoute(addresses[i][0], addresses[i][1]), 100);
        });
    </script>
</body>
</html>
I'm aware that there are a lot of similar questions on SO. But none of them worked for me.
 
     
    