diff --git a/src/MAUI/Maui.Samples/Samples/Search/FindPlace/FindPlace.xaml.cs b/src/MAUI/Maui.Samples/Samples/Search/FindPlace/FindPlace.xaml.cs index a3e18b778a..b02657456d 100644 --- a/src/MAUI/Maui.Samples/Samples/Search/FindPlace/FindPlace.xaml.cs +++ b/src/MAUI/Maui.Samples/Samples/Search/FindPlace/FindPlace.xaml.cs @@ -137,6 +137,10 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the geocode parameters. GeocodeParameters parameters = new GeocodeParameters(); + + // Request that the "Address" attribute is included with results, to display in callouts. + parameters.ResultAttributeNames.Add("Address"); + try { // Get the MapPoint for the current search location. @@ -146,6 +150,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re if (searchLocation != null) { parameters.PreferredSearchLocation = searchLocation; + + // Raise MinScore to a non-zero value, otherwise PreferredSearchLocation has no effect. + parameters.MinScore = 1; } // Update the search area if desired. @@ -174,24 +181,18 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the GraphicsOverlay so that results can be drawn on the map. GraphicsOverlay resultOverlay = new GraphicsOverlay(); + var symbol = await GetPinSymbolAsync(); + // Add each address to the map. foreach (GeocodeResult location in locations) { // Get the Graphic to display. - Graphic point = await GraphicForPoint(location.DisplayLocation); + var point = new Graphic(location.DisplayLocation, symbol); // Add the specific result data to the point. point.Attributes["Match_Title"] = location.Label; - - // Get the address for the point. - IReadOnlyList addresses = await _geocoder.ReverseGeocodeAsync(location.DisplayLocation); - - // Add the first suitable address if possible. - if (addresses.Any()) - { - point.Attributes["Match_Address"] = addresses.First().Label; - } + point.Attributes["Match_Address"] = location.Attributes["Address"]; // Add the Graphic to the GraphicsOverlay. resultOverlay.Graphics.Add(point); @@ -212,7 +213,10 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re } } - private async Task GraphicForPoint(MapPoint point) + /// + /// Creates and returns a "Pin" symbol used to mark search results on the MapView. + /// + private async Task GetPinSymbolAsync() { // Get current assembly that contains the image. Assembly currentAssembly = Assembly.GetExecutingAssembly(); @@ -230,7 +234,7 @@ private async Task GraphicForPoint(MapPoint point) // is on the point rather than the image's true center. pinSymbol.LeaderOffsetX = 30; pinSymbol.OffsetY = 14; - return new Graphic(point, pinSymbol); + return pinSymbol; } private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.GeoViewInputEventArgs e) diff --git a/src/WPF/WPF.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs b/src/WPF/WPF.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs index 72122cae65..2c319d6406 100644 --- a/src/WPF/WPF.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs +++ b/src/WPF/WPF.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs @@ -147,6 +147,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the geocode parameters. GeocodeParameters parameters = new GeocodeParameters(); + // Request that the "Address" attribute is included with results, to display in callouts. + parameters.ResultAttributeNames.Add("Address"); + // Get the MapPoint for the current search location. MapPoint searchLocation = await GetSearchMapPoint(locationText); @@ -154,6 +157,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re if (searchLocation != null) { parameters.PreferredSearchLocation = searchLocation; + + // Raise MinScore to a non-zero value, otherwise PreferredSearchLocation has no effect. + parameters.MinScore = 1; } // Update the search area if desired. @@ -179,24 +185,17 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the GraphicsOverlay so that results can be drawn on the map. GraphicsOverlay resultOverlay = new GraphicsOverlay(); + var symbol = await GetPinSymbolAsync(); // Add each address to the map. foreach (GeocodeResult location in locations) { // Get the Graphic to display. - Graphic point = await GraphicForPoint(location.DisplayLocation); + var point = new Graphic(location.DisplayLocation, symbol); // Add the specific result data to the point. point.Attributes["Match_Title"] = location.Label; - - // Get the address for the point. - IReadOnlyList addresses = await _geocoder.ReverseGeocodeAsync(location.DisplayLocation); - - // Add the first suitable address if possible. - if (addresses.Any()) - { - point.Attributes["Match_Address"] = addresses[0].Label; - } + point.Attributes["Match_Address"] = location.Attributes["Address"]; // Add the Graphic to the GraphicsOverlay. resultOverlay.Graphics.Add(point); @@ -218,9 +217,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re } /// - /// Creates and returns a Graphic associated with the given MapPoint. + /// Creates and returns a "Pin" symbol used to mark search results on the MapView. /// - private async Task GraphicForPoint(MapPoint point) + private async Task GetPinSymbolAsync() { // Hold a reference to the picture marker symbol. PictureMarkerSymbol pinSymbol; @@ -245,7 +244,7 @@ private async Task GraphicForPoint(MapPoint point) pinSymbol.OffsetY = 14; } - return new Graphic(point, pinSymbol); + return pinSymbol; } /// diff --git a/src/WinUI/ArcGIS.WinUI.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs b/src/WinUI/ArcGIS.WinUI.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs index 28a93f36d4..9b61f358d8 100644 --- a/src/WinUI/ArcGIS.WinUI.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs +++ b/src/WinUI/ArcGIS.WinUI.Viewer/Samples/Search/FindPlace/FindPlace.xaml.cs @@ -10,6 +10,7 @@ using ArcGIS.Samples.Shared.Managers; using Esri.ArcGISRuntime.Data; using Esri.ArcGISRuntime.Geometry; +using Esri.ArcGISRuntime.Location; using Esri.ArcGISRuntime.Mapping; using Esri.ArcGISRuntime.Symbology; using Esri.ArcGISRuntime.Tasks.Geocoding; @@ -144,6 +145,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the geocode parameters GeocodeParameters parameters = new GeocodeParameters(); + // Request that the "Address" attribute is included with results, to display in callouts. + parameters.ResultAttributeNames.Add("Address"); + try { // Get the MapPoint for the current search location @@ -153,6 +157,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re if (searchLocation != null) { parameters.PreferredSearchLocation = searchLocation; + + // Raise MinScore to a non-zero value, otherwise PreferredSearchLocation has no effect. + parameters.MinScore = 1; } // Update the search area if desired @@ -181,24 +188,17 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re // Create the GraphicsOverlay so that results can be drawn on the map GraphicsOverlay resultOverlay = new GraphicsOverlay(); + var symbol = await GetPinSymbolAsync(); // Add each address to the map foreach (GeocodeResult location in locations) { // Get the Graphic to display - Graphic point = await GraphicForPoint(location.DisplayLocation); + var point = new Graphic(location.DisplayLocation, symbol); // Add the specific result data to the point point.Attributes["Match_Title"] = location.Label; - - // Get the address for the point - IReadOnlyList addresses = await _geocoder.ReverseGeocodeAsync(location.DisplayLocation); - - // Add the first suitable address if possible - if (addresses.Any()) - { - point.Attributes["Match_Address"] = addresses[0].Label; - } + point.Attributes["Match_Address"] = location.Attributes["Address"]; // Add the Graphic to the GraphicsOverlay resultOverlay.Graphics.Add(point); @@ -220,9 +220,9 @@ private async Task UpdateSearch(string enteredText, string locationText, bool re } /// - /// Creates and returns a Graphic associated with the given MapPoint + /// Creates and returns a "Pin" symbol used to mark search results on the MapView /// - private async Task GraphicForPoint(MapPoint point) + private async Task GetPinSymbolAsync() { // Get current assembly that contains the image Assembly currentAssembly = GetType().GetTypeInfo().Assembly; @@ -240,7 +240,7 @@ private async Task GraphicForPoint(MapPoint point) // is on the point rather than the image's true center pinSymbol.LeaderOffsetX = 30; pinSymbol.OffsetY = 14; - return new Graphic(point, pinSymbol); + return pinSymbol; } ///