Bing Maps GetRoute gives '0x8004231C' error

情到浓时终转凉″ 提交于 2019-12-01 10:26:44

问题


I'm trying to show a route from point-to-point on the bing-maps (testing on real device). I've entered 2 waypoints (GeoCoordinate) and I'm trying to get the route via the Windows PhoneToolKit using the await query.GetRouteAsync(). Unfortunately, I'm getting an unknown error:

The result of the async call:

'e.Result' threw an exception of type 'System.Reflection.TargetInvocationException'

The inner exception:

Exception from HRESULT: 0x8004231C

I've checked the MSDN website and noticed that this errorcode is not listed in the errorlist...

The related code is below. I've used the exact same code as in the sample set of the Windows Phone Toolkit, but removed the things which has nothing to do with getting the route:

    private async void BtnShowRoute_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        try
        {
            RouteQuery query = new RouteQuery();
            List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();

            wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
            wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));

            query.Waypoints = wayPoints;

            Route route = await query.GetRouteAsync();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            throw;
        }
    }

I have no idea what is going wrong here. Does anyone else experienced this issue? If so, did you resolve it? And how?

Note: I'm running Windows Phone 8.1. Dev Preview


回答1:


This happens when the underlying service call times out before completing the query. Hopefully this will be fixed in next version , but for now you can use following code:

private async void BtnShowRoute_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
            RouteQuery query = new RouteQuery();
            List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();

            wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
            wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));

            query.Waypoints = wayPoints;
   query .QueryCompleted += geoQ_QueryCompleted;
            query.GetRouteAsync();


    }  
 private void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
        {
            try
            {
                Route myRoute = e.Result;
            }
            catch (TargetInvocationException)
            {
                Thread.Sleep(1000); // waiting for  completing the query
                    geoQ_QueryCompleted(sender, e);
            }

        }


来源:https://stackoverflow.com/questions/23218392/bing-maps-getroute-gives-0x8004231c-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!