我有一个 SPA,我需要能够提供两点之间的用户方向。我希望方向的工作方式与他们目前在谷歌地图的网络版本上所做的相同。IE.https://www.google.ca/maps/dir/在由谷歌网络版本托管的情况下,当您请求方向时,它会给您考虑交通的最快路线...(参见截图)
目前,当我使用以下代码发出请求时,它只返回一个不考虑流量的路由。
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 正确的方法来做到这一点?
检查DirectionService.route
返回的路由数,回调将有一个DirectionsResult
对象,其中包含一个DirectionsRoute
数组,其中包含有关其组成的腿和步骤的信息。
如果它只返回 1 个路由,请尝试在DirectionsRequest
对象中将provideRouteAlternatives
设置为 true。
快乐编码!
TyBourque。我认为目前的 google map API 不支持带有流量层的方向图。它只能使用嵌入式地图 API。
如果您已经找到了最佳解决方案(不使用嵌入式地图 API),请在此处写入
当做
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(76条)