Google maps API - 保存更改(标记)方向

时间:2011-09-16 14:47:03

标签: javascript google-maps-api-3

我正在使用谷歌地图api v3。当我计算方式(基于保存在变量中的点)之后,只需移动一个标记(改变方式) - 如何保存此更改? 我需要这个,因为当我改变标记位置并在那之后 - 改变旅行模式:新的方式是计算而不改变标记......

我厌倦了这个:http://vikku.info/programming/google-maps-v3/draggable-directions/saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm

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总是返回空数组......

1 个答案:

答案 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;