8

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.

1
  • Can you please answer your own question. Just copy paste your answer into the box below and mark as answered :) Mar 5, 2013 at 19:30

1 Answer 1

1

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.