I made myself a routes manager with a couple of options (like avoidTolls, travelMode, avoidHighways, waypoints) and draggable routes.
I Created var lastRequest = []
to store DirectionsRequest properties
from the last render.
The code looks like this:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var directions = parseDirections(response, mode, tolls)
directionsDisplay.setDirections(response)
}
});
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
refreshReq(directionsDisplay.getDirections())
})
function refreshReq(response)
{
//
}
I'm stuck finding a solution to refresh on directions_changed
my lastRequest['waypoints']
with new data from a response
so my script will be able to store a waypoints object and redo lastRequest
any time I want.
Difficulty comes when I take from response
the waypoints Array like I need.
Tried couple variants:lastRequest['waypoints'] = response['routes'][0]['legs'][0]['via_waypoints']
but that was not that.
Next step was to regenerate every waypoint one by one with new google.maps.LatLng()
but for some reason not worked even after I pushed them in array with eval().
Changed stopover to false/true, tried different things but nothing, must be missing something.
points js array that I generated by php needed refresh from via_waypoints
for (var p in req.routes[0].legs[0].via_waypoints)
points[p]['location'] = req.routes[0].legs[0].via_waypoints[p]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With