/// <summary> /// Update the UI based on the results of a Cloud Geocoding Query /// </summary> private void UpdateSearchResultsOnUI(CloudGeocodingResult searchResult) { // Clear the locations list and existing location markers on the map SimpleMarkerOverlay geocodedLocationOverlay = (SimpleMarkerOverlay)mapView.Overlays["Geocoded Locations Overlay"]; geocodedLocationOverlay.Markers.Clear(); lsbLocations.ItemsSource = null; geocodedLocationOverlay.Refresh(); // Update the UI with the number of results found and the list of locations found txtSearchResultsDescription.Text = $"Found {searchResult.Locations.Count} matching locations."; lsbLocations.ItemsSource = searchResult.Locations; if (searchResult.Locations.Count > 0) { lsbLocations.IsVisible = true; lsbLocations.SelectedItem = searchResult.Locations[0]; } }
/// <summary> /// Search for an address using the GeocodingCloudClient and update the UI /// </summary> private async void Search_Click(object sender, EventArgs e) { await CollapseExpander(); // Perform some simple validation on the input text boxes if (await ValidateSearchParameters()) { // Run the Cloud Geocoding query CloudGeocodingResult searchResult = await PerformGeocodingQuery(); // Handle an error returned from the geocoding service if (searchResult.Exception != null) { await DisplayAlert("Error", searchResult.Exception.Message, "OK"); return; } // Update the UI based on the results UpdateSearchResultsOnUI(searchResult); } }
/// <summary> /// Search for an address using the GeocodingCloudClient /// </summary> private async Task <CloudGeocodingResult> PerformGeocodingQuery() { // Show a loading graphic to let users know the request is running loadingIndicator.IsRunning = true; loadingLayout.IsVisible = true; CloudGeocodingOptions options = new CloudGeocodingOptions(); // Set up the CloudGeocodingOptions object based on the parameters set in the UI options.MaxResults = int.Parse(txtMaxResults.Text); options.SearchMode = ((string)cboSearchType.SelectedItem) == "Fuzzy" ? CloudGeocodingSearchMode.FuzzyMatch : CloudGeocodingSearchMode.ExactMatch; options.LocationType = (CloudGeocodingLocationType)Enum.Parse(typeof(CloudGeocodingLocationType), (string)cboLocationType.SelectedItem); options.ResultProjectionInSrid = 3857; // Run the geocode string searchString = txtSearchString.Text.Trim(); CloudGeocodingResult searchResult = await geocodingCloudClient.SearchAsync(searchString, options); // Hide the loading graphic loadingIndicator.IsRunning = false; loadingLayout.IsVisible = false; return(searchResult); }