Bharat Bhatiya Bharat Bhatiya - 27 days ago 14
Javascript Question

google api waypoint need to remove dynamically waypoint from display route

I am trying to remove waypoint from google map route using button click. But there is some problem while searching and removing element and redrawing directions with available elements.

Please check here jsfiddle:
link

There is on button click function added to remove waypoint from route:

function removewaypoint()
{...}


Here jsfiddle contain two issues:
1. Remove element from
waypts
array and
2. Redraw map route with new
waypts
array its also not working

Answer

Hello In remove waypoints you can add id to marker and then during removecode u can try to compare with marker id (which u want to remove). Please provide full code to get the exact solution.

var nwaypts=[];
                        var j=0;
                        for ( var i = 0; i < waypts.length ; i++) {
                            if(waypts[i].id!=removemarkerid){
                                nwaypts[j]=waypts[i];
                                j++;
                            }
                        }
                        waypts=nwaypts;