Export (0) Print
Expand All

RouteLeg Class

Bing

Represents a leg of a route. A route leg is the part of the route between two stop waypoints.

Properties

Name Type Description

endTime

DateTime

The end time of the route leg. This property only applies when the routeMode of the DirectionsRequestOptions is set to transit.

endWaypointLocation

Location

The location of the last waypoint of this leg.

itineraryItems

DirectionsStep[]

The directions steps associated with this route leg.

originalRouteIndex

number

The index of the route to which this route leg belongs.

startTime

DateTime

The start time of the route leg. This property only applies when the routeMode of the DirectionsRequestOptions is set to transit.

startWaypointLocation

Location

The location of the first waypoint of this route leg.

subLegs

RouteSubLeg[]

The sub legs of this route leg. A sub leg of a route is the part of the route between a stop point and a via point or between two via points.

summary

RouteSummary

The summary which describes this route leg.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

      <script type="text/javascript">
         
         var map = null;

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Bing Maps Key"});
            Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: directionsModuleLoaded });

         }

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

            // Create start and end waypoints and add them to the route
            var startWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Seattle, WA"});
            var endWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Bellevue, WA"});

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

            // Specify a handler for when the directions are calculated
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', displayMessage);
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayError);

            // Calculate directions, which displays a route on the map
            directionsManager.calculateDirections();

         } 


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

         function displayError(e)
         {
            alert("An error has occurred calculating the directions.");
         }

      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>       
   </body>
</html>
Show:
© 2014 Microsoft