2012-04-13 2 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

나는 여러 경로없는 일을합니다. 나는 많이 봤지만 아무것도 찾을 수 없었다!

다음은 내가 시도한 것입니다. 현재 GoogleMap으로의 경로에서 웨이 포인트를 경로 객체에 저장 될 수 있도록


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 말해 주시겠습니까?

답변

0

접근 방식을 약간 변경하고 getPoints -method를 Route-object에 추가했습니다.

이 방법은 원점, 경유지 및 대상으로 구성된 배열을 반환하므로 어딘가에 쉽게 전달할 수 있습니다. (배열의 각 항목에 배열 될 것이다 위도, LNG]) 일 완전히

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

+0

!!! 대단히 감사합니다 !!!!! – Ryo

관련 문제