private void CalculateRoute(GeocodeResult[] locations=null)
{
// Preparing a request for route calculation.
var request = new RouteRequest()
{
Culture = CultureInfo.CurrentUICulture.Name,
Waypoints = new ObservableCollection<Waypoint>(),
// Don't raise exceptions.
ExecutionOptions = new UsingBingMaps.Bing.Route.ExecutionOptions()
{
SuppressFaults = true
},
// Only accept results with high confidence.
Options = new RouteOptions()
{
RoutePathType = RoutePathType.Points
}
};
if (from_address == false)
{
Waypoint w_to = new Waypoint();
Waypoint w_from = new Waypoint();
w_to.Location = x_to;
w_from.Location = x_from;
request.Waypoints.Add(w_from);
request.Waypoints.Add(w_to);
}
else
{
foreach (var result in locations)
{
request.Waypoints.Add(GeocodeResultToWaypoint(result));
}
}
// Get credentials and only then place an async call on the route service.
_credentialsProvider.GetCredentials(credentials =>
{
// Pass in credentials for web services call.
// Replace with your own Credentials.
request.Credentials = credentials;
// Make asynchronous call to fetch the data.
_routeClient.CalculateRouteAsync(request);
});
}