I currently have a DirectionsRenderer function that properly routes To and From fields on my page. After the routing is done I grab the overview_path and then load elements from a Fusion Table based on the path. Once this is done I've set up a listener looking for 'directions_changed', which would indicate a waypoint as such:
google.maps.event.addListener(directionsDisplay, 'directions_changed', function(){
var wypnt = directionsDisplay.getDirections().routes[0].legs[0].via_waypoints.toString().match(/[^()]+/);
wypnt.toString().split(",");
wypnt = new google.maps.LatLng(wypnt[1],wypnt[0]);
var waypoint = [];
waypoint.push({ location: wypnt, stopover: true });
route(waypoint);
});
Once I pass it back to the route() function (the function that works normally with the To and From fields), I have this section of code:
if(waypoint){
var request = {
origin: document.getElementById("search-input-from").value,
destination: document.getElementById("search-input-to").value,
waypoints: waypoint,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
}
else{
var request = {
origin: document.getElementById("search-input-from").value,
destination: document.getElementById("search-input-to").value,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
}
The rest of the code is based off the following if statement:
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
//do stuff
}
else {
alert("Directions query failed: " + status);
}
};
Unfortunately all I'm getting back is "Directions query failed: ZERO_RESULTS". Any idea why this is happening? I'm not sure if the way I'm forming the waypoint is wrong or something else.