我正在使用谷歌地图api v3。当我计算方式(基于保存在变量中的点)之后,只需移动一个标记(改变方式) - 如何保存此更改? 我需要这个,因为当我改变标记位置并在那之后 - 改变旅行模式:新的方式是计算而不改变标记......
var new_waypoints = directionsDisplay.directions.routes[0].legs[0];
origin = new_waypoints.start_location;
destination = new_waypoints.end_location;
var wp = new_waypoints.via_waypoints;
var w = [];
alert(wp.length);
for(var i=0; i<wp.length; i++)
{
w[i] = [wp[i].lat(),wp[i].lng()]
alert('w');
}
waypoints = w;
但是new_waypoints.via_waypoints总是返回空数组......
答案 0 :(得分:0)
我找到了解决方案!
var new_waypoints = directionsDisplay.directions.routes[0].legs[0];
var waypoints_count = directionsDisplay.directions.routes[0].legs.length;
var w = [];
origin = new_waypoints.start_location;
for(var i = 1; i<waypoints_count; ++i)
{
w.push({ location: directionsDisplay.directions.routes[0].legs[i].start_location, stopover: true });
}
destination = directionsDisplay.directions.routes[0].legs[waypoints_count-1].end_location;
waypoints = w;