谷歌地图directionsService.route
需要使用JavaScript添加或删除waypoint
。
可以使用以下代码将新点添加到数组中:
waypts.push({ location: "Rome, Italy", stopover: true });
从数组中删除航点时出现问题
这是一个数据示例,可以更详细地解释;
需要从上述JavaScript对象数组中删除点1或点2,如何实现。
然后,我将为每次从上述数组中绘制路径创建新的路标,命名为
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
];