【问题标题】:Order with directionsService - google maps使用方向服务订购 - 谷歌地图
【发布时间】:2018-09-29 00:54:23
【问题描述】:

我对就近订单有疑问。 我有一个对象数组:

waypoints = [
 location:{
 lat: -8.116597,
 lng: -79.0347417
},
location:{
 lat: -8.120997,
 lng: -79.038355
},
location:{
 lat: -8.120151,
 lng: -79.037014
},
location:{
 lat: -8.119195,
 lng: -79.036657
},
]

我以这种方式发送到谷歌地图:

this.$refs.mapa.$mapCreated.then(() => {
          this.directionsService = new google.maps.DirectionsService();
          this.directionsDisplay.setMap(this.$refs.mapa.$mapObject);
          this.directionsService.route({
            origin: { lat: -8.0828174, lng: -79.0953881 },
            destination: this.waypoints[this.waypoints.length - 1].location,
            waypoints: this.waypoints,
            travelMode: 'DRIVING',
            optimizeWaypoints: true,
          }, (r, status) => {
              if (status === 'OK') {
                this.directionsDisplay.setDirections(r);
                console.log(r.routes[0].waypoint_order);
                }
            });
        });

其中应该给我带来最接近原点的点,如果有的话。当我按照发送对象数组的顺序进行更改时,就会出现问题。例如,如果我订购,我会打印以下订单:

[0, 1, 2, 4, 3, 5]

但是如果我改变了排列的顺序,然后再订购,打印另一个顺序:

[1, 2, 3, 4, 0, 5]

我不知道为什么会发生这种情况,因为如果不是仓位(lat, lng),您不必导入运输订单

有什么遗漏吗?

【问题讨论】:

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


    【解决方案1】:

    origindestination 在请求中是固定的。 optimizeWaypoints 只优化了航点的顺序。

    您的代码使用“航路点”之一作为目的地。

    相关问题:

    【讨论】:

    • 那我应该删除命运吗?
    • 需要一个目的地。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 2017-02-23
    • 2016-09-18
    • 1970-01-01
    • 2015-10-25
    • 2014-01-15
    • 1970-01-01
    相关资源
    最近更新 更多