[英]Edit an optimized Google Maps route
所需功能
从数据库收集预定义的起点,终点和中间航路点后,请查询Google Maps API V3以:
a)根据给定的航点优化路线。
b)在地图上显示该路线。 显示最佳航点顺序。
c)使用户可以编辑航点顺序。 请注意:不需要拖动航路点的标记来更改其地址。 所需的行为是按照API的顺序列出路点列表,然后能够手动编辑顺序并相应地更新地图。
d)将API的答案和用户可能的编辑之后的最终顺序保存回数据库。
目前正在做什么
以下代码涵盖了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);
}
});
}
题
API优化并显示后,API中是否有任何方法可以支持手动编辑航点的顺序?
是否有任何类似解决方案的示例可以帮助我解决此问题?
附加信息
我需要支持手动编辑路点顺序的原因是,有时这些中途停留所代表的交付会受到时间限制。 因此,用户偶尔会希望修改中途停留顺序,以使其更方便地在方便的时间交付,例如:一天的结束,早晨的路线开始等。
在此先感谢您的帮助。
没有内置的实现,但是实现起来并不难。
可以通过路线的waypoint_order
属性来检索优化的航路点的顺序。 您可以使用此顺序来创建可排序的列表,当列表将被重新排序时,发送具有重新排序的航点且optimizeWaypoints
-option设置为false
的新请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.