Waypoint Class

Bing
 

Represents a route waypoint.

Name

Definition

Description

Waypoint

Waypoint(options:WaypointOptions)

Initializes a new instance of the Waypoint class.

Name

Definition

Return Value

Description

clear

clear()

None

Clears all options associated with this waypoint.

dispose

dispose()

None

Releases any resources associated with the waypoint.

getAddress

getAddress()

string

Returns the address associated with the waypoint.

getBusinessDetails

getBusinessDetails()

BusinessDetails

Returns the business details associated with the waypoint.

getDisambiguationContainer

getDisambiguationContainer()

DOMElement

Returns the container element for the waypoint disambiguation list.

getDisambiguationResult

getDisambiguationResult()

Disambiguation

Returns the result of the waypoint geocoding disambiguation.

getLocation

getLocation()

Location

Returns the location of the waypoint.

getPushpin

getPushpin()

Pushpin

Returns the custom pushpin associated with this waypoint, if one has been specified.

getShortAddress

getShortAddress()

string

Returns the short address for the waypoint.

isExactLocation

isExactLocation()

boolean

Returns a boolean indicating whether the waypoint location is the exact location.

isViapoint

isViapoint()

boolean

Returns a boolean value indicating whether the waypoint is a via point. A via point is a location that your route is guaranteed to pass through. There can be multiple via points between two stop points.

setOptions

setOptions(options:WaypointOptions)

None

Sets options for the waypoint. For these options to take effect, you must recalculate the route.

Name

Arguments

Description

changed

WaypointEventArgs

Occurs when the any properties of the waypoint change or are updated.

geocoded

WaypointEventArgs

Occurs when a geocoding request for the waypoint’s address is made.

reverseGeocoded

WaypointEventArgs

Occurs when a reverse geocoding request for the waypoint’s location is made. This happens when no address is provided for the waypoint, or if the waypoint is dragged (in which case its location is changed).

<!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;
         var directionsManager = 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
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

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

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

            // Set the id of the div to use to display the directions
            directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('itineraryDiv') });

            // Specify a handler for when an error occurs
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayError);

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



         } 

         function displayError(e)
         {
            // Display the error message
            alert(e.message);

            // If the error is a disambiguation error, display the results.
            if (e.responseCode == Microsoft.Maps.Directions.RouteResponseCode.waypointDisambiguation)
            {
               SelectFirstDisambiguationResult();
            }

         }



         function SelectFirstDisambiguationResult()
         {
            var results = "";

            var waypoints = directionsManager.getAllWaypoints();

            var recalculate = false;

            var i = 0;
            for (i=0; i<waypoints.length; i++)
            {

               var disambigResult = waypoints[i].getDisambiguationResult();

               if (disambigResult != null)
               {
                  // Reset the address to the first business or location suggestion
                  var firstAddress = disambigResult.businessSuggestions.length > 0 ? disambigResult.businessSuggestions[0].address : disambigResult.locationSuggestions[0].suggestion;
                  waypoints[i].setOptions({ address: firstAddress });

                  // Set the recalculate flag since the waypoint address was changed
                  recalculate = true;
               }
            }

            if (recalculate)
            {
               directionsManager.calculateDirections();
            }
        }



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