Is it possible to get all driving directions with a specified FROM and TO location in UWP using Bing Map SDK? (just like windows 10 map app)
Asked
Active
Viewed 342 times
1 Answers
1
Yes: Get a driving or walking route and directions by calling the methods of the MapRouteFinder class - for example, GetDrivingRouteAsync or GetWalkingRouteAsync. The MapRouteFinderResult object contains a MapRoute object that you access through its Route property.
When you request a route, you can specify the following things: •You can provide a start point and end point only, or you can provide a series of waypoints to compute the route. •You can specify optimizations - for example, minimize the distance. •You can specify restrictions - for example, avoid highways.
You can use sample code like this one:
private async void GetRouteAndDirections()
{
// Start at Microsoft in Redmond, Washington.
BasicGeoposition startLocation = new BasicGeoposition();
startLocation.Latitude = 47.643;
startLocation.Longitude = -122.131;
Geopoint startPoint = new Geopoint(startLocation);
// End at the city of Seattle, Washington.
BasicGeoposition endLocation = new BasicGeoposition();
endLocation.Latitude = 47.604;
endLocation.Longitude = -122.329;
Geopoint endPoint = new Geopoint(endLocation);
// Get the route between the points.
MapRouteFinderResult routeResult =
await MapRouteFinder.GetDrivingRouteAsync(
startPoint,
endPoint,
MapRouteOptimization.Time,
MapRouteRestrictions.None);
if (routeResult.Status == MapRouteFinderStatus.Success)
{
// Display summary info about the route.
tbOutputText.Inlines.Add(new Run()
{
Text = "Total estimated time (minutes) = "
+ routeResult.Route.EstimatedDuration.TotalMinutes.ToString()
});
tbOutputText.Inlines.Add(new LineBreak());
tbOutputText.Inlines.Add(new Run()
{
Text = "Total length (kilometers) = "
+ (routeResult.Route.LengthInMeters / 1000).ToString()
});
tbOutputText.Inlines.Add(new LineBreak());
tbOutputText.Inlines.Add(new LineBreak());
// Display the directions.
tbOutputText.Inlines.Add(new Run()
{
Text = "DIRECTIONS"
});
tbOutputText.Inlines.Add(new LineBreak());
foreach (MapRouteLeg leg in routeResult.Route.Legs)
{
foreach (MapRouteManeuver maneuver in leg.Maneuvers)
{
tbOutputText.Inlines.Add(new Run()
{
Text = maneuver.InstructionText
});
tbOutputText.Inlines.Add(new LineBreak());
}
}
}
else
{
tbOutputText.Text =
"A problem occurred: " + routeResult.Status.ToString();
}
}
More info here : https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631250.aspx#getting_a_route_and_directions

Stéphanie Hertrich
- 705
- 4
- 9
-
Can you please mark as anwser to close the thread ? Many thanks :) – Stéphanie Hertrich May 19 '16 at 12:09