// Geocode input address and add result graphics to the map private async void FindButton_Click(object sender, RoutedEventArgs e) { try { progress.Visibility = Visibility.Visible; listResults.Visibility = Visibility.Collapsed; _graphicsOverlay.GraphicsSource = null; // Street, City, State, ZIP Dictionary<string, string> address = new Dictionary<string, string>(); if (!string.IsNullOrEmpty(InputAddress.Text)) address.Add("Street", InputAddress.Text); if (!string.IsNullOrEmpty(City.Text)) address.Add("City", City.Text); if (!string.IsNullOrEmpty(State.Text)) address.Add("State", State.Text); if (!string.IsNullOrEmpty(Zip.Text)) address.Add("ZIP", Zip.Text); if (_locatorTask == null) { var path = System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, LOCATOR_PATH); _locatorTask = await Task.Run<LocalLocatorTask>(() => new LocalLocatorTask(path)); } var candidateResults = await _locatorTask.GeocodeAsync( address, new List<string> { "Match_addr" }, MyMapView.SpatialReference, CancellationToken.None); _graphicsOverlay.GraphicsSource = candidateResults .Select(result => new Graphic(result.Location, new Dictionary<string, object> { { "Locator", result } })); await MyMapView.SetViewAsync(ExtentFromGraphics().Expand(2)); } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { var _x = new MessageDialog(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray())).ShowAsync(); } else { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } } catch (System.Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } finally { progress.Visibility = Visibility.Collapsed; if (_graphicsOverlay.GraphicsSource != null) listResults.Visibility = Visibility.Visible; } }
// Geocode input address and add result graphics to the map private async void FindButton_Click(object sender, RoutedEventArgs e) { try { progress.Visibility = Visibility.Visible; listResults.Visibility = Visibility.Collapsed; graphicsLayer.GraphicsSource = null; // Street, City, State, ZIP Dictionary<string, string> address = new Dictionary<string, string>(); if (!string.IsNullOrEmpty(InputAddress.Text)) address.Add("Street", InputAddress.Text); if (!string.IsNullOrEmpty(City.Text)) address.Add("City", City.Text); if (!string.IsNullOrEmpty(State.Text)) address.Add("State", State.Text); if (!string.IsNullOrEmpty(Zip.Text)) address.Add("ZIP", Zip.Text); if (_locatorTask == null) _locatorTask = await Task.Run<LocalLocatorTask>(() => new LocalLocatorTask(LOCATOR_PATH)); var candidateResults = await _locatorTask.GeocodeAsync( address, new List<string> { "Match_addr" }, mapView.SpatialReference, CancellationToken.None); graphicsLayer.GraphicsSource = candidateResults .Select(result => new Graphic(result.Location, new Dictionary<string, object> { { "Locator", result } })); await mapView.SetViewAsync(ExtentFromGraphics()); } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) MessageBox.Show(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray())); else MessageBox.Show(ex.Message); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } finally { progress.Visibility = Visibility.Collapsed; if (graphicsLayer.GraphicsSource != null) listResults.Visibility = Visibility.Visible; } }
// Geocode input address and add result graphics to the map private async void FindButton_Click(object sender, RoutedEventArgs e) { try { progress.Visibility = Visibility.Visible; listResults.Visibility = Visibility.Collapsed; _graphicsOverlay.GraphicsSource = null; // Street, City, State, ZIP Dictionary <string, string> address = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(InputAddress.Text)) { address.Add("Street", InputAddress.Text); } if (!string.IsNullOrEmpty(City.Text)) { address.Add("City", City.Text); } if (!string.IsNullOrEmpty(State.Text)) { address.Add("State", State.Text); } if (!string.IsNullOrEmpty(Zip.Text)) { address.Add("ZIP", Zip.Text); } if (_locatorTask == null) { _locatorTask = await Task.Run <LocalLocatorTask>(() => new LocalLocatorTask(LOCATOR_PATH)); } var candidateResults = await _locatorTask.GeocodeAsync( address, new List <string> { "Match_addr" }, MyMapView.SpatialReference, CancellationToken.None); _graphicsOverlay.GraphicsSource = candidateResults .Select(result => new Graphic(result.Location, new Dictionary <string, object> { { "Locator", result } })); await MyMapView.SetViewAsync(ExtentFromGraphics().Expand(2)); } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { MessageBox.Show(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray())); } else { MessageBox.Show(ex.Message); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } finally { progress.Visibility = Visibility.Collapsed; if (_graphicsOverlay.GraphicsSource != null) { listResults.Visibility = Visibility.Visible; } } }