CalculateRouteError event

2 posts, 0 answers
  1. Simon
    Simon avatar
    35 posts
    Member since:
    Oct 2010

    Posted 24 May 2017 Link to this post


    I have just upgraded to 2017R2 and have moved the code to use the Bing Restful api for the maps.

    However, when we calculate a route, we now have to handle two events, the CalculateRouteCompleted and the CalculateRouteError.  The problem is that when we get the completed event we have access to the UserData that I sent with the async request (I can then tie the response back to the original request), but with the error event we just get the exception that is returned from Bing (a less than helpful bad request).  Is there a reason why we don't also get the UserData back?

    My scenario is that I asynchronously send off searches to create a drive zone around a point.  Before, I would send off say 16 requests and even if they are bad requests (e.g. they are in the sea), I would get the result back and I could then adjust the search.

    So in summary, how can I link a CalculateRouteError event back to the request that caused it?

  2. Petar Mladenov
    Petar Mladenov avatar
    3018 posts

    Posted 25 May 2017 Link to this post

    Hello Simon,

    You can try overriding BingRestMapProvider class and its OnCalculatedRouteCompleted method like so:

    public class CustomBingRestMapProvider : BingRestMapProvider
            protected override void OnCalculateRouteCompleted(object sender, DownloadStringCompletedEventArgs e)
                // This will fire CalculateRouteCompleted / CalculateRouteError
                base.OnCalculateRouteCompleted(sender, e);
                if (e.Error != null)
                    object userState = e.UserState;
                    // your logic here.

    We hope this is a good option for you.

    Petar Mladenov
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top