【问题标题】:Google maps api fastest route around traffic谷歌地图 api 最快的交通路线
【发布时间】: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


    【解决方案1】:

    检查DirectionService.route返回的路线数量,回调将有一个DirectionsResult对象和DirectionsRoute数组,其中包含有关其组成的腿和步骤的信息。

    如果它只返回 1 个路由,请尝试在您的 DirectionsRequest 对象中将 provideRouteAlternatives 设置为 true。

    编码愉快!

    【讨论】:

      【解决方案2】:

      泰布尔克。 我认为当前的谷歌地图 API 不支持带交通层的方向图。 它仅在使用嵌入式地图 API 时可用。

      如果您已经找到最佳解决方案(不使用嵌入式地图 API),请写在这里

      问候

      【讨论】:

      • 这并不能真正回答问题。如果您有不同的问题,可以通过单击 来提问。一旦你有足够的声望,你也可以添加赏金来吸引更多关注这个问题。
      • 嗨,awh112 我已经回答了解决方案是使用嵌入式地图 API。我认为这就是上述问题的答案。
      猜你喜欢
      • 2016-08-28
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多