我正在使用 bing 网络服务查找两地之间的最短路线。
但是我得到了这个奇怪的错误:
public imagine_cup.RoutingService.RouteResponse EndCalculateRoute(System.IAsyncResult result) {
object[] _args = new object[0];
imagine_cup.RoutingService.RouteResponse _result = ((imagine_cup.RoutingService.RouteResponse)(base.EndInvoke("CalculateRoute", _args, result))); //error in this line
return _result;
}
错误指出这是服务器错误。
这是我的代码:
public void CalculateRoute(List<Pushpin> wayPoints)
{
// Set the credentials.
routeService.RouteRequest routeRequest = new routeService.RouteRequest();
routeRequest.Credentials = new Credentials();
routeRequest.Credentials.ApplicationId = _applicationId;
// Return the route points so the route can be drawn.
routeRequest.Options = new routeService.RouteOptions();
routeRequest.Options.RoutePathType = routeService.RoutePathType.Points;
// Set the waypoints of the route to be calculated using the Geocode Service results stored in the geocodeResults variable.
routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<routeService.Waypoint>();
//Adding way points
foreach (Pushpin ps in wayPoints)
{
routeRequest.Waypoints.Add(PushpinToWaypoint(ps));
}
// Make the CalculateRoute asnychronous request.
_routeService.CalculateRouteAsync(routeRequest);
}
我已经更新了我的必应 map key ,所以原因不是旧 key
最佳答案
好的,现在我们已经在评论中确定问题出在起点和终点之间的距离上,这就是我的答案。
你不能路由很远的距离(即使在 Bing maps 上也不行(他们显然使用相同的路由服务))......服务就是这样创建的。如果您真的非常需要这个,您可以考虑一些将距离划分为更小块的算法。然后你会在较小的 block 之间找到多条路线,然后将它们连接起来(在 map 上绘制它们连接起来)......
这里明显的问题是:如何找到能够将路径分成 block 的中间点?好吧,一种相当简单的方法是找到点之间的空气距离(参见 Haversine formula)然后将其分成相等的部分。显然,这意味着您将影响最终路线,并且它几乎肯定不会是起点和终点之间的最短路线。此外,它可能会将您的用户引导到甚至没有道路的奇怪地方(森林、沙漠、海洋)。小题外话:我不知道为什么有人会同时在两个遥远的国家/地区之间路由,除了只是为了找出行车距离,他们可以在网上的某个地方做...
关于c# - Bing路由服务故障exception1错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756105/