2016-09-29 9 views
0

새로운 빙지도 v8을 시험 중입니다. 이 예를 따르십시오 : http://www.bing.com/api/maps/sdk/mapcontrol/isdk#directionsCreateTransitRoute+JS빙지도 v8 getRouteResult가 정의되지 않은 문자를 반환합니다.

경로 결과 (directionsManager.getRouteResult())를 가져와야하지만 undefined을 반환합니다.

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` 
}); 

답변

2

비동기 경로 계산이 완료되기 전에 경로 결과를 요청하고 있습니다.

이처럼 directionsManager 개체의 directionsUpdated 이벤트에 대한 핸들러로 getRouteResult 전화를 이동

: 당신은 directionsEvent 개체의 동일한 속성에 액세스 할 수 있습니다

Microsoft.Maps.Events.addHandler(
    directionsManager, 
    'directionsUpdated', 
    function (directionsEvent) 
    { 
    var route = directionsManager.getRouteResult(); 
    }); 

.

+0

작품입니다. 고마워요! –