使用 directionsService 订购 - google 地图
Order with directionsService - google maps
我对最近的订单有疑问。
我有一个对象数组:
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
},
]
这样我发送到google 地图:
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]
我不知道为什么会这样,因为如果不是位置(纬度,经度),您不必导入运输订单
是不是少了什么?
请求中固定了origin
和destination
。 optimizeWaypoints
只优化 waypoints.
的顺序
您的代码使用 "waypoints" 之一作为目的地。
相关问题:
我对最近的订单有疑问。 我有一个对象数组:
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
},
]
这样我发送到google 地图:
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]
我不知道为什么会这样,因为如果不是位置(纬度,经度),您不必导入运输订单
是不是少了什么?
请求中固定了origin
和destination
。 optimizeWaypoints
只优化 waypoints.
您的代码使用 "waypoints" 之一作为目的地。
相关问题: