Bing Map优化路线

时间:2016-08-09 20:53:06

标签: javascript bing-maps

由于我需要优化一些路线,因此我一直在研究Bing地图。每条路线有10站。我想根据bing map的建议重新排序航点

我的代码是在javascript中

directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });

var startWaypoint = new Microsoft.Maps.Directions.Waypoint({
     location: new Microsoft.Maps.Location(XX, YY),                
});

directionsManager.addWaypoint(startWaypoint);

for (var i = 0; i < 10; i++) {

    var waypoint = new Microsoft.Maps.Directions.Waypoint({
        location: new Microsoft.Maps.Location(XX, YY),
    })

    directionsManager.addWaypoint(waypoint);
}

var endWaypoint = new Microsoft.Maps.Directions.Waypoint({
     location: new Microsoft.Maps.Location(XX, YY),                
});

directionsManager.addWaypoint(endWaypoint);

directionsManager.setRequestOptions({
            routeDraggable: false,
            routeOptimization: Microsoft.Maps.Directions.RouteOptimization.shortestDistance,
            routeMode: Microsoft.Maps.Directions.RouteMode.driving
        });

Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', function(result) {
    console.log(result);
});

directionsManager.calculateDirections();

在事件directionsUpdated上,当调用api时,不会重新排序航点。始终与我发送的订单相同

Bing&#34;&#34;&#34;优化&#34; Bing Map Routes API是否可以重新排序航路点?参数发送?或者它只能最大限度地减少2点之间的距离?

1 个答案:

答案 0 :(得分:0)

Bing Maps不提供旅行推销员类型路线优化。 Bing地图中提到的优化是关于如何通过航路点按照提供的顺序计算路线。例如,最短距离,最短时间,最短的交通时间。 可以使用路由服务生成距离矩阵,然后通过代码实现TSP算法。以下是使用JavaScript执行此操作的代码示例:https://1drv.ms/u/s!AgFqp4QkIjUNo5cpCk-qqNaQnxWT5w