2012-04-13 59 views
1

我希望通過可拖動的路標顯示多個路線,並在每次調用Route.prototype.setWayPoints()時保存每個路線點與對象或數據庫中的原點,目的地相關聯。在Google地圖v3中處理多個路線點

這傢伙正在用可拖動的路標(並將它們保存在數據庫中)的單一路線。

http://vikku.info/programming/google-maps-v3/draggable-directions/saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm

不是我想要多條路線之一。我GOOGLE了很多,但找不到任何東西!

這是我的嘗試。


function Route(origin, destination){ 
    this.origin = origin; // LatLng 
    this.destination = destination; //LatLng 
    this.way_points = null; 
}; 

Route.prototype.drawRoute = function(){ 
       this.dser.route({'origin': this.origin, 
        'destination': this.destination, 
        'waypoints': this.way_points, 
        'travelMode': google.maps.DirectionsTravelMode.DRIVING}, 
        function(res,sts) { 
          if(sts=='OK'){ 
           var dren = new google.maps.DirectionsRenderer({ 'draggable':true }); 
           dren.setMap(map); //global variable 'map' 
           dren.setDirections(res); 
          } 
        }); 
}; 

Route.prototype.setGMap = function(map){ 
   this.dren.setMap(map); 
}; 

Route.prototype.setWayPoints = function(){ 
  this.way_points = //... what should I do? 
}; 


/* --- main part --- */ 

r0 = new Route(new google.maps.LatLng(30, 31), new google.maps.LatLng(40, 41)); 
r0.drawRoute(); 

// User drags and drops the route on the browser 

r0.setWayPoints(); // newly added waypoints should be stored in r0.way_points 

r1 = new Route(new google.maps.LatLng(50, 51), new google.maps.LatLng(60, 61)); 
r1.drawRoute(); 

// User drags and drops the route on the browser 

r1.setWayPoints(); // newly added waypoints should be stored in r1.way_points 

誰能告訴我如何實現Route.prototype.setWayPoints這樣在當前的GoogleMap的航線航點可存儲在Route對象?

回答

0

我已經稍微改變了方法,並在路由對象中添加了一個getPoints-方法。

此方法將返回由原點,航點和目的地組成的數組,因此您可以輕鬆地將它傳遞到某處。 (所述陣列的每個項目將是一個數組[緯度,經度])

http://jsfiddle.net/doktormolle/fjUqK/

+0

即完全工作!非常感謝你!!!!! – Ryo 2012-04-14 07:15:37

相關問題