-1
是否可以使用Bing Map SDK在UWP中的指定FROM和TO位置獲取所有行車路線? (就像Windows 10地圖應用程序)在UWP中使用Bing Map SDK獲取所有路線
是否可以使用Bing Map SDK在UWP中的指定FROM和TO位置獲取所有行車路線? (就像Windows 10地圖應用程序)在UWP中使用Bing Map SDK獲取所有路線
是: 通過調用MapRouteFinder類的方法獲取駕車或步行路線和路線 - 例如GetDrivingRouteAsync或GetWalkingRouteAsync。 MapRouteFinderResult對象包含您通過其Route屬性訪問的MapRoute對象。
當您請求路線時,您可以指定以下內容: •您只能提供起點和終點,或者您可以提供一系列路點以計算路線。 •您可以指定優化 - 例如,最小化距離。 •您可以指定限制 - 例如,避開高速公路。
您可以使用示例代碼像這樣的:
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();
}
}
能否請您標記爲anwser關閉線程?非常感謝 :) –