【发布时间】:2017-01-06 22:05:40
【问题描述】:
我有一个 SPA,我需要能够提供两点之间的用户方向。我希望方向的工作方式与他们目前在网络版谷歌地图上的工作方式相同。 IE。 https://www.google.ca/maps/dir/ 在由 google 网络版托管时,当您请求路线时,它会为您提供考虑交通流量的最快路线...(见屏幕截图)
目前,当我使用以下代码发出请求时,它只返回一个不考虑流量的单一路由。
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);
}
});
有人知道正确的方法吗?
【问题讨论】:
标签: google-maps google-maps-api-3 google-directions-api