根據this,directionRenderer對象的方法setRouteIndex()應設置DirectionsResult對象中路由的(從零開始)索引以進行呈現。setRouteIndex在Google地圖方向上不工作JS api v3
這裏是我做了什麼:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setRouteIndex(1);
console.log(directionsDisplay.getRouteIndex());
directionsDisplay.setDirections(response);
console.log(directionsDisplay.getRouteIndex());
} });
我知道有替代路線查詢我跟做。這裏,第一個console.log(directionsDisplay.getRouteIndex());
給出了路線編號。 ,多數民衆贊成沒關係,但在setDirections
的執行後,secong日誌給出值0 !.這意味着第一條路線。我已經啓用,替代路線,provideRouteAlternatives:真,我還發起對象是這樣的:
var rendererOptions = {
routeIndex:1
}
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
但它仍然顯示的路線沒有。 0,不是數字1.這裏是我的webpage,請檢查來源。提前致謝。
感謝,可能我沒有得到它,我認爲setDirection正在做,從directionsService.route獲得結果並在地圖中繪製路線。如果我評論該線路,它不會在地圖中繪製路線,現在我將如何繪製路線,而不使用setDirections。 –
謝謝,我正在嘗試這個,我會得到使用getDirections()的新路線,然後我要通過它setDirections。 –
請參閱文檔中的示例:https://google-developers.appspot.com/maps/documentation/javascript/examples/directions-complex – Marcelo