【发布时间】: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