Maps Bing映射v8 GetRouterResult返回未定义
我正在尝试新的Bing地图v8。我举一个例子: 我需要获取路由结果(directionsManager.GetRouterResult()),但返回Maps Bing映射v8 GetRouterResult返回未定义,maps,bing,bing-api,bing-maps,Maps,Bing,Bing Api,Bing Maps,我正在尝试新的Bing地图v8。我举一个例子: 我需要获取路由结果(directionsManager.GetRouterResult()),但返回未定义的 var map = new Microsoft.Maps.Map(document.getElementById('rs-mapa-elem'), { credentials: 'Your Bing Maps Key', center: new Microsoft.Maps.Location(47.606209, -122.
未定义的
var map = new Microsoft.Maps.Map(document.getElementById('rs-mapa-elem'), {
credentials: 'Your Bing Maps Key',
center: new Microsoft.Maps.Location(47.606209, -122.332071),
zoom: 12
});
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
// Set Route Mode to transit
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.transit });
var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: 'Redmond', location: new Microsoft.Maps.Location(47.67683029174805, -122.1099624633789) });
var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: 'Seattle', location: new Microsoft.Maps.Location(47.59977722167969, -122.33458709716797) });
directionsManager.addWaypoint(waypoint1);
directionsManager.addWaypoint(waypoint2);
// Set the element in which the itinerary will be rendered
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') });
directionsManager.calculateDirections();
var route =directionsManager.getRouteResult();
console.log(route); // Returns `undefined`
});
您正在异步方向计算完成之前请求路由结果
将getRouteResult调用移动到directionsManager
对象的DirectionsUpdate事件的处理程序中,如下所示:
Microsoft.Maps.Events.addHandler(
directionsManager,
'directionsUpdated',
function (directionsEvent)
{
var route = directionsManager.getRouteResult();
});
您可以访问directionsEvent
对象中的相同属性。在异步方向计算完成之前,您正在请求路由结果
将getRouteResult调用移动到directionsManager
对象的DirectionsUpdate事件的处理程序中,如下所示:
Microsoft.Maps.Events.addHandler(
directionsManager,
'directionsUpdated',
function (directionsEvent)
{
var route = directionsManager.getRouteResult();
});
您可以访问directionsEvent
对象中的相同属性