2011-09-16 35 views
0

我正在使用谷歌地圖api v3。當我計算方式(基於保存在變量中的點數)之後,只需移動一個標記(改變方式) - 我如何保存這個變化? 我需要的,因爲當我改變標記的位置,之後 - 改變出行方式:無標記變化的新方式計算...谷歌地圖API - 保存更改(標記)方向

我厭倦了這樣的: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始終返回空陣列...

回答

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;