This example demonstrates how to calculate a route between several waypoints and change the appearance of a route path by means of the Microsoft Bing Route web service.
To calculate a route between waypoints, call the BingRouteDataProvider.CalculateRoute method and pass a list of waypoints as its argument.
To customize the route path appearance, do the following:
- Handle the BingRouteDataProvider.RouteCalculated event;
- Access the route path using the RouteCalculationResult object inside the BingRouteDataProvider.RouteCalculated event handler's BingRouteCalculatedEventArgs;
- Create a MapPolylinewith calculated route points. To access the route points collection, use the BingRouteResult.RoutePath property;
- Customize the stroke and stroke width of the map polyline using the MapItem.Stroke and MapItem.StrokeWidth properties.
The map pushpins are generated automatically at each route waypoint position because the InformationDataProviderBase.GenerateLayerItemsproperty is set to true by default. Note that the pushpins' text contains an empty string.
To number route waypoints (from start to finish) in the pushpin, handle the InformationDataProviderBase.LayerItemsGeneratingevent and modify the MapPointer.Text property.
Note that if you run this sample as is, you will get a warning message saying that the specified Bing Maps key is invalid. To learn more about Bing Map keys, please refer to the How to: Get a Bing Maps Keytutorial.