사용자가 입력란에서 시작점과 종료점을 검색하고 나면 경로가 그려지면 웨이 포인트를 추가하고 드래그하여 경로를 사용자 정의 할 수있는 Google지도가 있습니다. . 제출시 경로는 XML로 저장되고 필요할 때 새지도에 다시 그려집니다. 문제는 그 순간에 시작점과 끝점 만 XML에 저장된다는 것입니다.Google지도 웨이 포인트를 사용하여 경로를 다시 그리는 방법
나는이 문서에서 작업 해왔다 : https://developers.google.com/maps/documentation/javascript/directions#Waypoints, 그러나 나는 완전히 여기저기서 혼란 스럽다.
내가 제안한 방법은 시작 및 끝점과 동일하므로 위도 및 경도 값을 XML에 저장합니다. JS는 웨이 포인트 데이터를 얻습니다. 나는 배열을 구조화하는 방법을보기 위해 console.logged했습니다. 여기에있는 문제는 각 웨이 포인트 (둘 이상이있는 경우)를 반복하고 각 변수를 새 변수로 저장하여 PHP 제출을 위해 양식에 추가 할 수있는 방법을 모르겠다는 것입니다.
//What to do when a waypoint has been added/changed
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
var waypoints = directionsDisplay.getDirections().routes[0].legs[0].via_waypoints;
console.log(waypoints);
console.log(waypoints[0].kb);
});
내가 말했듯이, 아마도 쉬운 방법이있을 것입니다. 위의 시도는 지금까지 시도한 것입니다. 이합니다 ... CONSOLE.LOG (중간 점)의 결과
이 절약 PHP이다
$('form.add-journix').submit(function() {
$('#startlat').attr('value', startLatVal);
$('#startlng').attr('value', startLongVal);
$('#endlat').attr('value', endLatVal);
$('#endlng').attr('value', endLongVal);
});
그 값은 이하이다 숨겨진 입력을 제공하는 JS ... XML로는 ...
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("title", $row['title']);
$newnode->setAttribute("description", $row['description']);
$newnode->setAttribute("startlat", $row['startlat']);
$newnode->setAttribute("startlng", $row['startlng']);
$newnode->setAttribute("endlat", $row['endlat']);
$newnode->setAttribute("endlng", $row['endlng']);
}
echo $dom->saveXML();
경로를 저장하는 코드는 어떻게됩니까? 새로운 "경유"웨이 포인트를 추가하는 것은 꽤 간단합니다. – geocodezip
질문을 좀 더 자세히 업데이트했습니다. 감사. – GuerillaRadio
나는 당신이 [this] (http://www.geocodezip.com/v3_GoogleEx_directions-draggable_toXml.html)과 같은 것을 할 것이라고 생각했다. (문서의 [예제] (https://developers.google.com)를 기반으로한다./maps/documentation/javascript/directions # DraggableDirections)) – geocodezip