Desired functionality
从数据库收集预定义的开始,结束和中间Waypoint后,查询Google Maps API V3以:
a)根据给定的航路点优化路线 .
b)在 Map 上显示这样的路线 . 显示最佳航点订单 .
c)为用户提供编辑航点顺序的可能性 . 请注意:不希望拖动航点的标记来更改其地址 . 期望的行为是获得API订购的航点列表,然后能够手动编辑订单并相应地更新 Map .
d)在API回答和用户可能的编辑之后,将最终订单保存回数据库 .
What is currently working
以下代码涵盖了A点和B点中描述的功能:
function initialize() {
var mapOptions = {
zoom: 8, <!-- We can also support customizable zoom levels according to the size of delivery area !-->
center: region
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directionsPanel'));
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.getDirections());
});
calcRoute();
}
function calcRoute() {
var request = {
origin: 'Chemnitz, Germany', <!-- This will be the main address, we get it from the database. -->
destination: 'Chemnitz, Germany',
optimizeWaypoints: true,
waypoints:[{location: 'Mittweida, Germany'}, {location: 'Zwickau, Germany'}, {location: 'Dresden, Germany'}, {location: 'Freiberg, Germany'}], <!-- This will be the list of locations the truck has to visit, we get it from the database. -->
travelMode: google.maps.TravelMode.DRIVING <!-- Maps supports many types of transport, but we have to specify this is a particular vehicle. -->
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
Question
在API优化并显示后,API中是否有任何方法支持手动编辑航点的顺序?
是否有类似解决方案的示例可以帮助我解决此问题?
Additional information
我需要支持手动编辑航点订单的原因是,有时候,这些中途停留所代表的交付存在时间限制 . 因此,用户偶尔会想要修改中途停留顺序,以使它们在方便的时间更适当地交付,即:一天结束,早上路线的开始等 .
在此先感谢您的帮助 .
1 回答
没有内置的实现,但实现它并不困难 .
可以通过路线的
waypoint_order
-property来检索优化的航点的顺序 . 您可以使用此订单创建可排序列表,当列表将被重新排序时,使用重新排序的航点发送新请求,并将optimizeWaypoints
-option设置为false