void geocodeService_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e) { Exception error = e.Error; List<LocationForQuery> locations = new List<LocationForQuery>(); if (error == null) { try { GeocodeResult[] results = e.Result.Results; foreach (GeocodeResult result in results) { LocationForQuery location = new LocationForQuery() { name = result.DisplayName, boundingBox = new LocationRect() { Northeast = new GeoCoordinate(result.BestView.Northeast.Latitude, result.BestView.Northeast.Longitude), Southwest = new GeoCoordinate(result.BestView.Southwest.Latitude, result.BestView.Southwest.Longitude) }, confidence = (ViewModel.LocationServiceDataStructures.Confidence)(int)result.Confidence }; location.location = new GeoCoordinate() { Latitude = result.Locations[0].Latitude, Longitude = result.Locations[0].Longitude, Altitude = result.Locations[0].Altitude }; locations.Add(location); } } catch (Exception ex) { error = ex; } } Debug.Assert(error == null); if (LocationForAddress_Completed != null) { GeocodeState state = (GeocodeState)e.UserState; LocationForAddress_Completed(this, new LocationForAddressEventArgs( locations, state.Query, state.SearchNearLocation, error, state.CallerState )); } }
private void SearchByLocationCallback(LocationForQuery location, Exception error) { Dispatcher.BeginInvoke(() => { SearchStoryboard.Seek(TimeSpan.Zero); SearchStoryboard.Stop(); this.Focus(); }); if (error != null) { viewModel_ErrorHandler(this, new ViewModel.EventArgs.ErrorHandlerEventArgs(error)); } else if (location == null) { Dispatcher.BeginInvoke(() => MessageBox.Show(searchErrorMessage, "No results found", MessageBoxButton.OK)); } else { Dispatcher.BeginInvoke(() => { viewModel.CurrentViewState.CurrentRoute = null; viewModel.CurrentViewState.CurrentRouteDirection = null; viewModel.CurrentViewState.CurrentStop = null; viewModel.CurrentViewState.CurrentSearchLocation = location; Navigate(new Uri("/StopsMapPage.xaml", UriKind.Relative)); }); } }