Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refresh waypoints on directions_changed

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.

like image 204
Al Po Avatar asked Mar 07 '12 04:03

Al Po


1 Answers

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]
like image 65
Al Po Avatar answered Oct 11 '22 16:10

Al Po