0

我正在为 Bing 地图开发“快速道路”功能。我的想法是,一旦用户点击地图,DirectionsManager 类就会计算路线,这样如果用户想要制作一条绕曲线的路线,他们就不必多次点击。他们只需单击两次,页面将完成其余的工作。(顺便说一句,如果有人有更好的方法,请告诉我 - 这是我第一次通过解决方案。)

我正在尝试 MSDN 上的 DirectionsManager 示例,并减少了与 RouteLeg 类有关的示例代码 (http://msdn.microsoft.com/en-us/library/hh312823),我有以下基本代码:

function directionsModuleLoaded() {
    var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

    var startWaypoint = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(42.71926499622451,-84.57241695374249) });
    var endWaypoint = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(42.71390477940529,-84.5766870304942) });

    directionsManager.addWaypoint(startWaypoint);
    directionsManager.addWaypoint(endWaypoint);

    directionsManager.calculateDirections();
}

function displayMessage(e) {
    alert("The calculated route has " + e.route[0].routeLegs[0].itineraryItems.length + " direction steps.");
}

这确实有效。我输入一对纬度/经度值,它计算并显示“圆角”路线。我希望的是一种在路线的每个方向变化的部分放置一个 PushPin 的方法,所以如果需要三个小路线转弯,就会显示一个 PushPin,每个点都有一个两段相遇。那可能吗?

4

1 回答 1

0

您可以从 DirectionManager 类调用getAllWaypoints()来获取所有航点的数组。

对于每个航点,您可以调用getLocations()来获取航点对象的位置。

然后,您可以在每个位置创建一个图钉,方法是将 waypoint.getLocations() 传递给图钉构造函数以及任何其他设置选项,然后将图钉添加到地图。

于 2012-09-24T20:03:29.687 回答