1

我正在尝试在 bing-maps 上显示从点到点的路线(在真实设备上进行测试)。我已经输入了 2 个航点(GeoCoordinate),我正在尝试通过 Windows PhoneToolKit 使用await query.GetRouteAsync(). 不幸的是,我收到一个未知错误:

异步调用的结果:

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

内部异常:

Exception from HRESULT: 0x8004231C

我检查了MSDN 网站,发现此错误代码未列在错误列表中...

相关代码如下。我使用了与 Windows Phone Toolkit 示例集完全相同的代码,但删除了与获取路由无关的内容:

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

我不知道这里出了什么问题。有没有其他人遇到过这个问题?如果是这样,你解决了吗?如何?

注意:我运行的是 Windows Phone 8.1。开发预览

4

1 回答 1

1

当底层服务调用在完成查询之前超时时会发生这种情况。希望这将在下一个版本中修复,但现在您可以使用以下代码:

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

        }
于 2014-06-10T08:40:56.043 回答