private void CalculateRouteByLocation(Location from, Location to) { Debug.WriteLine("CalculateRouteByLocation"); var routeCalculator = new RouteCalculator( CredentialsProvider, to, from, Dispatcher, result => { // Clear the route collection to have only one route at a time. Routes.Clear(); // Clear previous route related itineraries. Settings.Itinerary= new ObservableCollection<ItineraryItem>(); // Create a new route based on route calculator result, // and add the new route to the route collection. var routeModel = new RouteModel(result.Result.RoutePath.Points); Routes.Add(routeModel); // Add new route itineraries to the itineraries collection. foreach (var itineraryItem in result.Result.Legs[0].Itinerary) { Settings.Itinerary.Add(itineraryItem); } // Set the map to center on the new route. var viewRect = LocationRect.CreateLocationRect(routeModel.Locations); Map.SetView(viewRect); //ShowDirectionsView(); }); // Display an error message in case of fault. routeCalculator.Error += r => MessageBox.Show(r.Reason); // Start the route calculation asynchronously. routeCalculator.CalculateAsync(); }
private void CalculateRouteByAddress( String From, String To) { Debug.WriteLine("CalculateRouteByAddress"); try { var routeCalculator = new RouteCalculator( CredentialsProvider, To, From, Dispatcher, result => { // Clear the route collection to have only one route at a time. Routes.Clear(); // Clear previous route related itineraries. //Itineraries.Clear(); // Create a new route based on route calculator result, // and add the new route to the route collection. var routeModel = new RouteModel(result.Result.RoutePath.Points); Routes.Add(routeModel); // Add new route itineraries to the itineraries collection. //foreach (var itineraryItem in result.Result.Legs[0].Itinerary) //{ // Itineraries.Add(itineraryItem); //} // Set the map to center on the new route. var viewRect = LocationRect.CreateLocationRect(routeModel.Locations); Map.SetView(viewRect); //ShowDirectionsView(); }); // Display an error message in case of fault. routeCalculator.Error += r => MessageBox.Show(r.Reason); // Start the route calculation asynchronously. routeCalculator.CalculateAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }