I am using the bing web service to find a shortest route between two places.
But I get this strange error:
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;
}
the error states that it is a Server error.
Here is my code:
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);
}
I have update my bing maps key, so the reason is not an old key
OK, now that we’ve established in the comments that the problem is in the distance between starting and ending point, here’s my answer.
You can’t route large distances (not even on Bing maps (they obviously use the same routing services))… The service is created that way. If you really need this badly, you could think of some algorithm which would divide the distance into smaller chunks. Then you would find multiple routes between smaller chunks, and afterwards connect them (draw them connected on the map)…
The obvious problem here is: how do you find the middle points to be able to divide the path in chunks? Well, one rather simple way would be to find the air distance between the points (see Haversine formula for that) and then divide it in equal parts. Obviously this means that you will be affecting the final route and that it almost definitely will not be the shortest route between the starting and ending point. Also, it may route your user to weird places (forests, deserts, sea) which don’t even have a road. Small digression: I don’t know why anyone would route between two distant countries/places at once except to just find out the driving distance, which they can do somewhere online…