private void CalculateRoute(GeocodeService.GeocodeResult[] results) { RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.CalculateRouteCompleted += new EventHandler <RouteService.CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted); RouteService.RouteRequest routeRequest = new RouteService.RouteRequest(); routeRequest.Credentials = new Credentials(); routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)myMap.CredentialsProvider).ApplicationId; routeRequest.Options = new RouteService.RouteOptions(); routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points; routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection <RouteService.Waypoint>(); foreach (GeocodeService.GeocodeResult result in results) { routeRequest.Waypoints.Add(GeoCodeResultToWaypoint(result)); } routeService.CalculateRouteAsync(routeRequest); }
private void GetRoute(List<Stop> stops) { // Create the service variable and set the callback method using the CalculateRouteCompleted property. RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.CalculateRouteCompleted += new EventHandler<RouteService.CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted); // Set the token. RouteService.RouteRequest routeRequest = new RouteService.RouteRequest(); routeRequest.Credentials = new Credentials(); routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)map1.CredentialsProvider).ApplicationId; // Return the route points so the route can be drawn. routeRequest.Options = new RouteService.RouteOptions(); routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points; routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>(); int max = stops.Count() > 25 ? 25 : stops.Count(); for (int i = 0; i < max; i++) { Stop stop = stops.ElementAt(i); RouteService.Waypoint srcWaypoint = new RouteService.Waypoint(); srcWaypoint.Location = new GeoCoordinate((double)stop.Latitude, (double)stop.Longitude); routeRequest.Waypoints.Add(srcWaypoint); } // Make the CalculateRoute asnychronous request. routeService.CalculateRouteAsync(routeRequest); }
// This method makes the initial CalculateRoute asynchronous request using the results of the Geocode Service. private void CalculateRoute(GeocodeService.GeocodeResult[] locations) { // Create the service variable and set the callback method using the CalculateRouteCompleted property. RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.CalculateRouteCompleted += new EventHandler<CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted); // Set the credentials. RouteService.RouteRequest routeRequest = new RouteService.RouteRequest(); routeRequest.Culture = MyMap.Culture; routeRequest.Credentials = new RouteService.Credentials(); routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)MyMap.CredentialsProvider).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>(); foreach (GeocodeService.GeocodeResult result in locations) { routeRequest.Waypoints.Add(GeocodeResultToWaypoint(result)); } // Make asynchronous call to fetch the data ... pass state object. // Make the CalculateRoute asnychronous request. routeService.CalculateRouteAsync(routeRequest); }