Back to Devexpress

AzureRouteDataProvider.CalculateRoute(List<RouteWaypoint>, AzureRouteOptions) Method

windowsforms-devexpress-dot-xtramap-dot-azureroutedataprovider-dot-calculateroute-x28-system-dot-collections-dot-generic-dot-list-devexpress-dot-xtramap-dot-routewaypoint-devexpress-dot-xtramap-dot-azurerouteoptions-x29.md

latest6.1 KB
Original Source

AzureRouteDataProvider.CalculateRoute(List<RouteWaypoint>, AzureRouteOptions) Method

Calculates a route based on origin, destination, waypoints, and calculation options.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public void CalculateRoute(
    List<RouteWaypoint> waypoints,
    AzureRouteOptions options
)
vb
Public Sub CalculateRoute(
    waypoints As List(Of RouteWaypoint),
    options As AzureRouteOptions
)

Parameters

NameTypeDescription
waypointsList<RouteWaypoint>

A list of RouteWaypoint objects.

| | options | AzureRouteOptions |

An AzureRouteOptions object that defines route calculation options passed to the Azure Maps Route service.

|

Remarks

Call one of the AzureRouteDataProvider.CalculateRoute method overloads to calculate a route between the origin and destination, passing through the specified waypoints.

The following example calculates a car-optimized route through the specified waypoints:

csharp
using DevExpress.XtraMap;
// ...
const string key = "your key";
// ...
private void Form1_Load(object sender, EventArgs e) {
    MapControl map = new MapControl();
    // Specify the map position on the form.           
    map.Dock = DockStyle.Fill;
    // Create a layer.
    ImageLayer image = new ImageLayer();
    image.DataProvider = new AzureMapDataProvider(){
        AzureKey = key,
    };
    AzureRouteDataProvider routeProvider = new AzureRouteDataProvider();
    routeProvider.AzureKey = key;
    // Create three waypoints and add them to the route waypoints list.
    List<RouteWaypoint> waypoints = new List<RouteWaypoint>();
    waypoints.Add(new RouteWaypoint("NY", new GeoPoint(41.145556, -73.995)));
    waypoints.Add(new RouteWaypoint("Oklahoma", new GeoPoint(36.131389, -95.937222)));
    waypoints.Add(new RouteWaypoint("Las Vegas", new GeoPoint(36.175, -115.136389)));
    // Call the AzureRouteDataProvider.CalculateRoute method.
    azureRoute.CalculateRoute(waypoints, new AzureRouteOptions() {
        TravelMode = AzureTravelMode.Car,
        AvoidTypes = AzureRouteAvoidType.AlreadyUsedRoads
    });
    InformationLayer route = new InformationLayer();
    route.DataProvider = routeProvider;
    map.Layers.AddRange(new LayerBase[] { image, route});
    this.Controls.Add(map);
}
vb
Imports DevExpress.XtraMap
' ...
Private Const key As String = "your key"
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim map As New MapControl()
    ' Specify the map position on the form.           
    map.Dock = DockStyle.Fill
    ' Create a layer.
    Dim image As New ImageLayer()
    image.DataProvider = New AzureMapDataProvider() With {.AzureKey = key}
    Dim routeProvider As New AzureRouteDataProvider()
    routeProvider.AzureKey = key
    ' Create three waypoints and add them to the route waypoints list.
    Dim waypoints As New List(Of RouteWaypoint)()
    waypoints.Add(New RouteWaypoint("NY", New GeoPoint(41.145556, -73.995)))
    waypoints.Add(New RouteWaypoint("Oklahoma", New GeoPoint(36.131389, -95.937222)))
    waypoints.Add(New RouteWaypoint("Las Vegas", New GeoPoint(36.175, -115.136389)))
    ' Call the AzureRouteDataProvider.CalculateRoute method.
    azureRoute.CalculateRoute(waypoints, New AzureRouteOptions() With {
      .TravelMode = AzureTravelMode.Car,
      .AvoidTypes = AzureRouteAvoidType.AlreadyUsedRoads
    })
    Dim route As New InformationLayer()
    route.DataProvider = routeProvider
    map.Layers.AddRange(New LayerBase() { image, route})
    Me.Controls.Add(map)
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CalculateRoute(List<RouteWaypoint>, AzureRouteOptions) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

map-for-winforms-azure-routing/CS/Form1.cs#L69

csharp
}
azureRoute.CalculateRoute(geoPoints.Select(point => new RouteWaypoint("", point)).ToList(), new AzureRouteOptions() {
    TravelMode = GetTravelMode(),

map-for-winforms-azure-routing/VB/Form1.vb#L65

vb
azureRoute.CalculateRoute(geoPoints.[Select](Function(point) New RouteWaypoint("", point)).ToList(), New AzureRouteOptions() With {.TravelMode = GetTravelMode(), .AvoidTypes = GetAvoidTypes()})
geoPoints.Clear()

See Also

AzureRouteDataProvider Class

AzureRouteDataProvider Members

DevExpress.XtraMap Namespace