0

我有一個SPA,我需要能夠提供兩點之間的用戶指導。我希望這些說明的工作方式與他們目前在谷歌地圖的網絡版上的工作方式相同。 IE瀏覽器。 https://www.google.ca/maps/dir/在由谷歌網頁版主辦,當你要求的方向,它會給你最快的路線考慮交通......(見截圖)谷歌地圖api最快路線圍繞交通

Google maps fastest route with traffic

目前,當我使用下面的代碼它只返回發出請求一條不考慮流量的單一路線。

var directionsService = this.get('directionsService'); 
    var directionsDisplay = this.get('directionsDisplay'); 
    directionsService.route({ 
     origin: new google.maps.LatLng(this.get('currentLocation.lat'),this.get('currentLocation.lng')), 
     destination: new google.maps.LatLng(toAddress.lat,toAddress.lng), 
     travelMode: 'DRIVING', 
     provideRouteAlternatives: true 
    }, function(response, status) { 
     if (status === 'OK') { 
     directionsDisplay.setDirections(response); 
     } else { 
     window.alert('Directions request failed due to ' + status); 
     } 
    }); 

有沒有人知道thr正確的方法來做到這一點?

回答

0

檢查返回的路線數DirectionService.route,回調將有一個DirectionsResult對象與DirectionsRoute數組,其中包含有關腿和其組成的步驟的信息。

如果它僅返回1路線,請嘗試在您的DirectionsRequest對象中將provideRouteAlternatives設置爲true。

快樂編碼!