【问题标题】:Edit an optimized Google Maps route编辑优化的 Google 地图路线
【发布时间】: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


    【解决方案1】:

    对此没有内置实现,但实现起来并不难。

    可以通过路线的waypoint_order-property 检索优化航点的顺序。你可以使用这个顺序来创建一个可排序的列表,当列表将被重新排序时发送一个新的请求,其中包含重新排序的航点并将optimizeWaypoints-选项设置为false

    【讨论】:

    • 太棒了,好像我把自己弄得太复杂了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2014-03-13
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多