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。

快乐编码!