【发布时间】:2014-09-09 09:11:57
【问题描述】:
所需功能
从数据库中收集预定义的开始、结束和中间路点后,查询 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 优化并显示航点顺序后手动编辑航点顺序?
是否有任何类似解决方案的示例可以帮助我解决此问题?
其他信息
我需要支持手动编辑航点订单的原因是,有时这些中途停留所代表的交付存在时间限制。因此,有时用户会希望修改中途停留的顺序,以使它们在方便的时间更合适地交付,即:一天结束,早上路线开始等。
提前感谢您的帮助。
【问题讨论】:
标签: javascript google-maps google-maps-api-3