我正在使用谷歌地圖,我有點卡在一點。我想爲我的源和目標點顯示替代路線。目前我正在使用完美工作的代碼並顯示正確的結果,但唯一的問題是此代碼顯示所有具有距離和時間的路線的infowindow
。它需要不同顏色的替代路線..谷歌地圖API-在信息窗口上顯示具有距離的替代路線
請幫我。
var request = {
origin: source,
destination: destination,
travelMode: google.maps.TravelMode.DRIVING,
provideRouteAlternatives: true,
optimizeWaypoints
unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(request,
function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var step=2;
for (var i = 0, len = response.routes.length; i < len; i++) {
new google.maps.DirectionsRenderer({
map: mapObject,
directions: response,
routeIndex: i
});
stepDisplay.setContent(response.routes[i].legs[i].steps[step].distance.text + "<br>" + response.routes[i].legs[i].steps[step].duration.text + " ");
stepDisplay.setPosition(response.routes[i].legs[i].steps[step].end_location);
stepDisplay.open(mapObject);
}
} else {
$("#error").append("Unable to retrieve your route<br />");
}
});
對不起。我很困惑你到底是什麼問題。該帖子的標題是**顯示與信息窗口**距離的替代路線**,但後來你提到***,但唯一的問題是,此代碼顯示infowindow所有路線與距離和時間***。你也提到***,它需要不同顏色的替代路線.. ***。 如果我的理解正確,是否只想在**主路由**上顯示'infoWindow'?而替代路線(線)有不同的顏色? –
我需要兩個幫助。 1)我需要infowindow(距離和時間)爲所有路線(替代和主要路線) 2)在所有路線行應該是不同的顏色 – user3724675