Bing Maps GetRoute gives '0x8004231C' erro

2020-03-30 07:31发布

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条回答
孤傲高冷的网名
2楼-- · 2020-03-30 08:23

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

        }
查看更多
登录 后发表回答