Google map directionsService.route
需要使用 javascript 添加删除 waypoint
。
可以使用代码向数组添加新点:
waypts.push({ location: "Rome, Italy", stopover: true });
从数组中删除航路点时出现问题
Here my some data example that can explain more brief;
Need to remove point 1 or point 2 from above javascript object array how do it possible.
Then I will create new waypts for each time route draw from above array named
nwaypts
.
var nwaypts = [
{ location: "Rome, Italy", stopover: true }, // xyz: start point
{ location: { lat: 42.2070007, lng: 12.48549939999998 }, stopover: true, id: "17167" }, // point 1
{ location: { lat: 42.3793831, lng: 12.82857039999999 }, stopover: true, id: "18823" }, // point 2
{ location: "Terni, Italy", stopover: true } // xyz: end point
];
最佳答案
您好,在删除航点中,您可以将 id 添加到标记,然后在 removecode 期间,您可以尝试与标记 id(您想要删除的)进行比较。请提供完整代码以获得确切的解决方案。
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;
关于Javascript数组对象需要删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40466934/