【问题标题】:No alternative routes with waypoints没有带有航点的替代路线
【发布时间】:2017-02-01 16:08:09
【问题描述】:

我无法使用DirectionsService.routeprovideRouteAlternatives 设置为true 并定义多个waypoints 获得替代路线。

the doc 中没有任何内容表明这是不可能的。那么是我运气不好还是你也遇到了同样的问题?

(当我删除航点时它确实有效......)

因为有些人要求我实施,我已经完成了一个快速的jsFiddle 来显示问题。检查控制台日志以查看有无航点的结果。

var directionsService;

function initMap() {
  directionsService = new google.maps.DirectionsService();
  computeFakeItinerary();
}

function computeFakeItinerary() {
  var start = {
    lat: 45.7579555,
    lng: 4.8351209
  };
  var end = {
    lat: 43.7383216,
    lng: 7.4069485
  };
  var waypoints = [{
    location: {
      lat: 45.18236,
      lng: 5.6997148
    },
    stopover: true
  }];

  directionsService.route({
    origin: start,
    provideRouteAlternatives: true,
    waypoints: waypoints,
    destination: end,
    travelMode: 'DRIVING'
  }, routeCallback);

  directionsService.route({
    origin: start,
    provideRouteAlternatives: true,
    waypoints: [],
    destination: end,
    travelMode: 'DRIVING'
  }, routeCallback);
}

function routeCallback(data, status) {
  if (status == 'OK') {
    if (data.geocoded_waypoints.length > 2) {
      console.log("With waypoints there is " + data.routes.length + " routes");
    } else {
      console.log("Without waypoints there is " + data.routes.length + " routes");

    }
  }
}

initMap();
<script src="https://maps.googleapis.com/maps/api/js">
</script>

【问题讨论】:

标签: javascript google-maps-api-3 directions google-directions-api


【解决方案1】:

Official answer 来自 Google:

感谢您提醒我们注意这一点。

这似乎是一个文档问题。我们提供替代路线 对于没有 optimize:true 且没有航点的查询。

我们要求更新文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2016-05-20
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多