【问题标题】:Get all directions using Bing Map SDK in UWP在 UWP 中使用 Bing Map SDK 获取所有方向
【发布时间】:2016-07-23 04:30:58
【问题描述】:

是否可以使用 Bing Map SDK 在 UWP 中获取具有指定 FROM 和 TO 位置的所有行车路线? (就像 Windows 10 地图应用程序)

【问题讨论】:

    标签: bing-maps uwp-xaml uwp-maps


    【解决方案1】:

    是的: 通过调用 MapRouteFinder 类的方法(例如 GetDrivingRouteAsync 或 GetWalkingRouteAsync)获取行车或步行路线和方向。 MapRouteFinderResult 对象包含一个 MapRoute 对象,您可以通过其 Route 属性访问该对象。

    当您请求路由时,您可以指定以下内容: •您可以只提供起点和终点,也可以提供一系列航路点来计算路线。 •您可以指定优化 - 例如,最小化距离。 •您可以指定限制 - 例如,避开高速公路。

    您可以使用这样的示例代码:

        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();
            }
    
        }
    

    更多信息在这里:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631250.aspx#getting_a_route_and_directions

    【讨论】:

    • 能否请您标记为 anwser 以关闭线程?非常感谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多