我试图在bing地图上显示点对点的路线(在真实设备上测试)。我已经输入了2个路点(GeoCoordinate),我正试图使用await query.GetRouteAsync()
通过Windows PhoneToolKit获取路线。不幸的是,我得到了一个未知的错误:
异步调用的结果:
'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。开发人员预览
当底层服务调用在完成查询之前超时时,就会发生这种情况。希望这将在下一个版本中得到修复,但现在您可以使用以下代码:
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);
}
}