在Windows Phone 8.0地图上绘制路线的问题 - 0x8004231C

时间:2015-04-26 04:55:21

标签: c# windows-phone-8 geolocation maps

我想创建一个应用程序,显示从我的位置到某个所需点的路线。问题是它有时是有效的(对于某些位置绘制路线)但在某些情况下我得到这个错误:

"System.Runtime.InteropServices.COMException (0x8004231C): Excepion from HRESULT: 0x8004231C.

此外,我遵循了此处的教程:https://msdn.microsoft.com/en-us/library/windows/apps/jj244363%28v=vs.105%29.aspx

这是我的代码:

private async void GetCoordinates()
    {
        // Get the phone's current location.
        Geolocator MyGeolocator = new Geolocator();
        MyGeolocator.DesiredAccuracyInMeters = 5;
        Geoposition MyGeoPosition = null;
        try
        {
            MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
            MyCoordinates.Add(new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude));
            Mapka.Center = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);

        }
        catch (UnauthorizedAccessException)
        {
            MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
        }
        catch (Exception ex)
        {
            // Something else happened while acquiring the location.
            MessageBox.Show(ex.Message);
        }
        Mygeocodequery = new GeocodeQuery();
        Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
        Mygeocodequery.SearchTerm = txt1.Text;
        Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);

        Mygeocodequery.QueryAsync();


            }
    void Mygeocodequery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
    {
        if (e.Error == null)
        {
            MyQuery = new RouteQuery();
            MyCoordinates.Add(e.Result[0].GeoCoordinate);
            MyQuery.Waypoints = MyCoordinates;
            MyQuery.QueryCompleted += MyQuery_QueryCompleted;
            MyQuery.RouteOptimization = RouteOptimization.MinimizeDistance;
            MyQuery.QueryAsync();

            Mygeocodequery.Dispose();
        }
        else
        {
            MessageBox.Show(e.Error.ToString());

        }
    }

    void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
    {
        if (e.Error == null)
        {

            Route MyRoute = e.Result;
            MapRoute MyMapRoute = new MapRoute(MyRoute);
            Mapka.AddRoute(MyMapRoute);
            Mapka.SetView(MyMapRoute.Route.BoundingBox);
            MessageBox.Show(MyMapRoute.Route.LengthInMeters.ToString());
            MyQuery.Dispose();
        }

        else
        {
            MessageBox.Show(e.Error.ToString());

        }
 }

也许有人有类似的问题并可以提供帮助?

1 个答案:

答案 0 :(得分:0)

它适用于我:

    GeoCoordinate myPosition = null;
    MapRoute MyMapRoute = null;
    RouteQuery route = null;

    private void getRouteTo(GeoCoordinate myPosition, GeoCoordinate destination)
    {
        if (MyMapRoute != null)
        {
            map.RemoveRoute(MyMapRoute);
            MyMapRoute = null;
            route = null;
        }
        route = new RouteQuery()
        {
            TravelMode = TravelMode.Driving,
            Waypoints = new List<GeoCoordinate>()
            {
                myPosition, 
                destination
            },
            RouteOptimization = RouteOptimization.MinimizeTime
        };
        route.QueryCompleted += routeQuery_QueryCompleted;
        route.QueryAsync();
    }
    void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
    {
        if (e.Error == null)
        {
            Route MyRoute = e.Result;

            MyMapRoute = new MapRoute(MyRoute);
            map.AddRoute(MyMapRoute);
            route.Dispose();
        }
    }