订购DirectionsService - 谷歌地图

问题描述 投票:0回答:1

我有接近订单的问题。我有一个对象数组:

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个回答
1
投票

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

您的代码使用其中一个“航点”作为目的地。

相关问题:

© www.soinside.com 2019 - 2024. All rights reserved.