This is a migrated thread and some comments may be shown as answers.

CalculateRouteError event

1 Answer 56 Views
Map
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 24 May 2017, 08:34 AM

Hi,

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?

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 25 May 2017, 06:47 AM
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.

Regards,
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.
Tags
Map
Asked by
Simon
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or