#StackBounty: #javascript #google-maps #google-maps-api-3 Google map api directions service gives OVER_QUERY_LIMIT while displaying rou…

Bounty: 50

I’m working with project module which is using google map api direction services to draw path between multiple markers.

Here is my code:

var iconsetngs = {
    path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};

//Initialize the Path Array
var path = new google.maps.MVCArray();

//Initialize the Direction Service
var service = new google.maps.DirectionsService();

var polylineoptns = {
    strokeOpacity: 0.8,
    strokeWeight: 3,
    strokeColor: '#4986E7',
    map: map,
    icons: [{
              repeat: '600px', //CHANGE THIS VALUE TO CHANGE THE DISTANCE BETWEEN ARROWS
              icon: iconsetngs,
              offset: '100%'
            }]
  };


  var poly = new google.maps.Polyline(polylineoptns);

  //Loop and Draw Path Route between the Points on MAP
  for (var i = 0; i < lat_lng.length; i++) {
      if ((i + 1) < lat_lng.length) {
           var src = lat_lng[i];
           var des = lat_lng[i + 1];
           poly.setPath(path);
           service.route({
           origin: src,
           destination: des,
           travelMode: google.maps.DirectionsTravelMode.DRIVING                              

},function (result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
               for (var i = 0, len = result.routes[0].overview_path.length; i < len; i++) { 
                  path.push(result.routes[0].overview_path[i]);
                }
              }
           });
     }
   }
}

It’s displaying route, but after some points, it’s break.
Here is the result.

enter image description here

I’m not sure where I’m wrong or missing anything!

Edit:

It gives a status of OVER_QUERY_LIMIT


Get this bounty!!!