javascript - Limits for Directions with Transit Travel Mode -
i'm trying 4 directions "transit" travel mode in map. limitation of 3 "transit" calls per pageview identified. wondering if there wrong code, or if limitation exists in paid version of google maps api v3.
<script> var directionsdisplay; var directionsservice = new google.maps.directionsservice(); var map; var coords = []; var coordsindex = 0; function initialize() { directionsdisplay = new google.maps.directionsrenderer(); var chicago = new google.maps.latlng(41.850033, -87.6500523); var mapoptions = { zoom: 7, maptypeid: google.maps.maptypeid.roadmap, center: chicago } map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); directionsdisplay.setmap(map); coords.push("-23.544721,-46.784817"); coords.push("-23.571372,-46.644323"); coords.push("-23.509219,-46.602631"); coords.push("-23.512052,-46.343422"); coords.push("-23.719354,-46.41552"); coordsindex = 0; calcroute(); } function calcroute() { var start = coords[coordsindex]; var end = coords[coordsindex + 1]; var request = { origin: start, destination: end, travelmode: google.maps.directionstravelmode.transit }; directionsservice.route(request, function (response, status) { coordsindex++; if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); var description = ''; (ndxroute = 0; ndxroute < response.routes.length; ndxroute++) { var route = response.routes[ndxroute]; (ndxleg = 0; ndxleg < route.legs.length; ndxleg++) { var leg = route.legs[ndxleg]; if (description != '') description += '<br />'; description += leg.start_location + ' -> ' + leg.end_location + '<br />'; (ndxstep = 0; ndxstep < leg.steps.length; ndxstep++) { var step = leg.steps[ndxstep]; description += ' ' + step.instructions + '<br />'; } } } document.all['instructions'].innerhtml += description; } else window.alert('error calling route method: ' + status.tostring()); }); } google.maps.event.adddomlistener(window, 'load', initialize); </script> <style> html, body { height: 100%; margin: 0; padding: 0; } #map-canvas, #map_canvas { height: 80%; } @media print { html, body { height: auto; } #map_canvas { height: 650px; } } #panel { position: absolute; top: 5px; left: 50%; margin-left: -180px; z-index: 5; background-color: #fff; padding: 5px; border: 1px solid #999; } </style> <body> <div id="map-canvas"> </div> <button id="nextbutton" onclick="javascript:calcroute()"> call next route</button> <div id="instructions"> </div> </body>
you can "hold off" increasing amounts of time when error. noticeable seems work number of routes have.
else if (status == google.maps.directionsstatus.over_query_limit) { coordsindex--; errorcount++ if (errorcount < 3) settimeout("calcroute()", 2000*errorcount); else window.alert('error calling route method ['+coordsindex+']: ' + status.tostring()); }
Comments
Post a Comment