javascript - Google Maps DirectionsService multiple calls -
does know why giving me directions n+1 routes. example a-b-c-d-e-f, give me following routes:
a-b
b-c (empty result)
c-d
d-e (empty result)
e-f
here's google maps code, , i'm calling (inside uiwebview):
showdirections([a, b, c, d, e], true);
var directionsservice = new google.maps.directionsservice(); function showdirections(locations, metric) { var units = metric ? google.maps.unitsystem.metric : google.maps.unitsystem.imperial; (i=0; i<locations.length-1; i++) { console.log('navigating: '+locations[i].title+' '+locations[i+1].title); var request = { origin: new google.maps.latlng(locations[i].location.lat, locations[i].location.lng), destination: new google.maps.latlng(locations[i+1].location.lat, locations[i+1].location.lng), travelmode: google.maps.directionstravelmode.driving, avoidhighways: !!(locations[i].avoidhighway), unitsystem: units }; settimeout(function() { getdirections(request); }, 2000); } window.location = 'directionsstatus://loaded'; } function renderdirections(directions) { var directionsdisplay = new google.maps.directionsrenderer; directionsdisplay.setpanel(document.getelementbyid('panel')); directionsdisplay.setdirections(directions); } function getdirections(request) { directionsservice.route(request, function(response, status) { if (status == google.maps.directionsstatus.ok) { renderdirections(response); } else { alert(status); window.location = 'directionsstatus://' + status; } }); }
Comments
Post a Comment