我对临近订单有疑问。 我有一个对象数组:
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]
我不知道为什么会发生这种情况,因为如果不是位置(纬度,经度),您不必导入装运单
是不是少了什么东西?
最佳答案
起点
和目的地
在请求中是固定的。 optimizeWaypoints
仅优化航点的顺序。
您的代码正在使用“路径点”之一作为目的地。
相关问题:
关于javascript - 订购路线服务 - 谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49905501/