2012-04-13 10 views
1

ドラッグ可能なウェイポイントで複数のルートを表示し、Route.prototype.setWayPoints()が呼び出されるたびに、起点、目的地、オブジェクトまたはデータベースに関連付けられた各ウェイポイントを保存します。Google Maps v3でウェイポイントで複数のルートを扱う

この男は、ドラッグ可能なウェイポイントのある単一のルートでそれをやっています(データベースに保存する)。

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

は、私は複数のルートではないものをしたいです。私はたくさんのグーグルで検索しましたが、何も見つかりませんでした!

これは私が試みたものです。


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 

誰もが、現在のGoogleマップ上のルートでのウェイポイントがルートオブジェクトに格納することができるようにRoute.prototype.setWayPointsを実装する方法を教えてもらえますか?

答えて

0

私は少しアプローチを変更し、getPointsメソッドをルートオブジェクトに追加しました。

このメソッドは、起点、ウェイポイント、および宛先からなる配列を返します。そのため、どこかに簡単に渡すことができます。 全く働い

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

+0

(アレイの各項目は、配列[LAT、LNG]あろう)!どうもありがとうございました!!!!! – Ryo

関連する問題