Bing地图路线优化
我正在尝试使用bing Maps生成一条优化的路线, https://lealen.microsoft.com/en-us/bingmaps/rest-services/examples/optimized-waypoints-waypoints-example#example 屏幕上的结果路线。对于普通路线,我正在使用此例程,该例程似乎足够好...
function traceRoute(){
infobox.setOptions({visible:false});
if(Object.entries(fromCoords).length !== 0 && Object.entries(toCoords).length !== 0){
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving });
var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: fromCoords.title, location: new Microsoft.Maps.Location(fromCoords.lat,fromCoords.long) });
var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: toCoords.title, location: new Microsoft.Maps.Location(toCoords.lat,toCoords.long) });
directionsManager.addWaypoint(waypoint1);
directionsManager.addWaypoint(waypoint2);
// Set the element in which the itinerary will be rendered
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') });
directionsManager.calculateDirections();
});
}
}
但是,我无法弄清楚如何使用优化的API呼叫进行相同的操作。是否可以添加指向DirectionsManager并设置优化标志的方法列表?
I am attempting to generate an optimized route using Bing Maps re this article, https://learn.microsoft.com/en-us/bingmaps/rest-services/examples/optimized-waypoints-example#example, but am struggling to know how to render the resultant route on screen. For normal routes I am using this routine which seems to work well enough...
function traceRoute(){
infobox.setOptions({visible:false});
if(Object.entries(fromCoords).length !== 0 && Object.entries(toCoords).length !== 0){
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving });
var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: fromCoords.title, location: new Microsoft.Maps.Location(fromCoords.lat,fromCoords.long) });
var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: toCoords.title, location: new Microsoft.Maps.Location(toCoords.lat,toCoords.long) });
directionsManager.addWaypoint(waypoint1);
directionsManager.addWaypoint(waypoint2);
// Set the element in which the itinerary will be rendered
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') });
directionsManager.calculateDirections();
});
}
}
However, I cannot figure out how to do they same with an optimised API call. Is it possible to add a list of way points to the directionsManager and set an Optimised flag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
挖掘文档并试图逆转指示模块/管理器,在模块中似乎没有任何支持此选项的支持。
一种解决方案是直接致电休息服务以获取航路点的优化订购,然后将这些订购的航点传递到Directions Manager。这将使您能够利用方向模块的渲染功能,从而使开发变得更加容易。
这是一个代码样本:
Digging through the documentation and trying to reverse engineer the directions module/manager, there doesn't appear to be any support for this option in the module.
One solution would be to call the REST service directly to get the optimized ordering of the waypoints, then pass those ordered waypoints into the directions manager. This will allow you to leverage the rendering capabilities of the directions module which will make development a lot easier.
Here is a code sample: