使用c#在地图UWP(windows 10 mobile)上绘制Rout

时间:2016-03-24 15:09:18

标签: c# win-universal-app bing-maps uwp-maps

我正在开发一个带有地图功能的UWP应用程序。 我有Rout绘图功能,我在这个功能中遇到了问题。

这是我的代码(在WP 8.1中完全正常运行)

public async Task DrawRouteOnMap(double StartLong, double StartLat, double EndLong, double EndLat)
    {
        // Start at Grand Central Station.
        BasicGeoposition startLocation = new BasicGeoposition();
        startLocation.Latitude = StartLat;
        startLocation.Longitude = StartLong;
        Geopoint startPoint = new Geopoint(startLocation);
        // End at Central Park.
        BasicGeoposition endLocation = new BasicGeoposition();
        endLocation.Latitude = EndLat;
        endLocation.Longitude = EndLong;
        Geopoint endPoint = new Geopoint(endLocation);
        // Get the route between the points.
        MapRouteFinderResult routeResult =
        await MapRouteFinder.GetDrivingRouteAsync(
          startPoint,
          endPoint,
          MapRouteOptimization.Distance,
          MapRouteRestrictions.None,
          290);

        if (routeResult.Status == MapRouteFinderStatus.Success)
        {
            // Use the route to initialize a MapRouteView.
            MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
            viewOfRoute.RouteColor = Windows.UI.Color.FromArgb(1, 43, 151, 71);
            viewOfRoute.OutlineColor = Windows.UI.Color.FromArgb(1, 43, 151, 71);

            //await new Windows.UI.Popups.MessageDialog(viewOfRoute.Route.EstimatedDuration.ToString()).ShowAsync();
            // Add the new MapRouteView to the Routes collection
            // of the MapControl.
            mapControl.Routes.Add(viewOfRoute);
            // Fit the MapControl to the route.
            await mapControl.TrySetViewBoundsAsync(
              routeResult.Route.BoundingBox,
              null,
              MapAnimationKind.Linear);
        }
    }

此代码的结果是

  

StartPointNotFound

我也尝试了一个没有希望的静态位置。

提前致谢

0 个答案:

没有答案