Azure Maps Route Matrix – Order of results
I’m working with the Route Matrix in Azure Maps, passing in multiple origins and multiple destinations.
I have a foreach loop getting the summary for each leg. The problem I think I have is I can’t tell what the points in the leg were. Are results always returned in the same order starting with the first origin and looping through the destinations then going to the second origin and so on?
For example (origin ordinal on left, destination ordinal on right)
[0][0]
[0][1]
[0][2]
[1][0]
[1][1]
[1][2]
[2][0]
[2][1]
[2][2]
Is there a way in the code below to programmatically get the origin and destination for each route summary?
MapsRoutingClient client = new MapsRoutingClient(credential);
RouteMatrixQuery routeMatrixQuery = new RouteMatrixQuery
{
Origins = new List<GeoPosition>()
{
new GeoPosition(42.3400064,-83.0481779),
new GeoPosition(46.4962385,-84.3575817),
new GeoPosition(45.0270536,-84.6891603)
},
Destinations = new List<GeoPosition>()
{
new GeoPosition(45.3760861, -84.9653651),
new GeoPosition(45.4297623,-84.9904332),
new GeoPosition(45.6426144,-85.0420799)
},
};
RouteMatrixOptions options = new RouteMatrixOptions(routeMatrixQuery)
{
// ignore current traffic issues
UseTrafficData = false
};
// Get results
Response<RouteMatrixResult> result = client.GetImmediateRouteMatrix(options);
// Route matrix result
foreach (IList<RouteMatrix> routeResult in result.Value.Matrix)
{
Console.WriteLine(“Route result:”);
foreach (RouteMatrix route in routeResult)
{
RouteLegSummary summary = route.Summary;
Console.WriteLine($”No traffic: {summary.NoTrafficTravelTimeInSeconds} seconds”);
Console.WriteLine($”Travel time: {summary.TravelTimeInSeconds} seconds”);
Console.WriteLine($”Travel length: {summary.LengthInMeters} meters”);
Console.WriteLine($”Departure at: {summary.DepartureTime.ToString()} meters”);
Console.WriteLine($”Arrive at: {summary.ArrivalTime.ToString()} meters”);
}
}
I’m working with the Route Matrix in Azure Maps, passing in multiple origins and multiple destinations. I have a foreach loop getting the summary for each leg. The problem I think I have is I can’t tell what the points in the leg were. Are results always returned in the same order starting with the first origin and looping through the destinations then going to the second origin and so on? For example (origin ordinal on left, destination ordinal on right)[0][0][0][1][0][2][1][0][1][1][1][2][2][0][2][1][2][2] Is there a way in the code below to programmatically get the origin and destination for each route summary?MapsRoutingClient client = new MapsRoutingClient(credential);
RouteMatrixQuery routeMatrixQuery = new RouteMatrixQuery
{
Origins = new List<GeoPosition>()
{
new GeoPosition(42.3400064,-83.0481779),
new GeoPosition(46.4962385,-84.3575817),
new GeoPosition(45.0270536,-84.6891603)
},
Destinations = new List<GeoPosition>()
{
new GeoPosition(45.3760861, -84.9653651),
new GeoPosition(45.4297623,-84.9904332),
new GeoPosition(45.6426144,-85.0420799)
},
};
RouteMatrixOptions options = new RouteMatrixOptions(routeMatrixQuery)
{
// ignore current traffic issues
UseTrafficData = false
};
// Get results
Response<RouteMatrixResult> result = client.GetImmediateRouteMatrix(options);
// Route matrix result
foreach (IList<RouteMatrix> routeResult in result.Value.Matrix)
{
Console.WriteLine(“Route result:”);
foreach (RouteMatrix route in routeResult)
{
RouteLegSummary summary = route.Summary;
Console.WriteLine($”No traffic: {summary.NoTrafficTravelTimeInSeconds} seconds”);
Console.WriteLine($”Travel time: {summary.TravelTimeInSeconds} seconds”);
Console.WriteLine($”Travel length: {summary.LengthInMeters} meters”);
Console.WriteLine($”Departure at: {summary.DepartureTime.ToString()} meters”);
Console.WriteLine($”Arrive at: {summary.ArrivalTime.ToString()} meters”);
}
} Read More