4
之間的情節路線我寫了這個無辜的javascript代碼,它可以讓用戶創建兩個標記,繪製它們之間的路由。它不工作,相反,它提供了一個奇怪的錯誤:谷歌地圖兩點
Uncaught TypeError: Cannot read property 'ya' of undefined
有人建議我什麼是錯在這裏:
// called upon a click
GEvent.addListener(map, "click", function(overlay,point) {
if (isCreateHeadPoint) {
// add the head marker
headMarker = new GMarker(point,{icon:redIcon,title:'Head'});
map.addOverlay(headMarker);
isCreateHeadPoint = false;
} else {
// add the tail marker
tailMarker = new GMarker(point,{icon:greenIcon,title:'Tail'});
map.addOverlay(tailMarker);
isCreateHeadPoint = true;
// create a path from head to tail
direction.load("from:" + headMarker.getPoint().lat()+ ", " + headMarker.getPoint().lng()+ " to:" + tailMarker.getPoint().lat() + "," + tailMarker.getPoint().lng(), { getPolyline: true, getSteps: true });
// display the path
map.addOverlay(direction.getPolyline());
}
});
該死!你偷走了我發現正確答案的喜悅;)魔法是var directions = new GDirections(map); 十分感謝您的回答 – user315067 2010-05-17 12:28:33
@ amarsh - 阿南德:大聲笑:) ......你也可以刪除'getPolyline:從'GDirectionsOptions' TRUE'選項,因爲默認情況下它仍然會加載折線時在地圖附加到方向對象。 – 2010-05-17 12:33:04
謝謝你。那是所有剪切/粘貼代碼。再次感謝您的幫助 – user315067 2010-05-17 12:39:21