Find places of interest near a location or within a specific area.
Use case
When getting directions or looking for nearby places, users may only know what the place has ("food"), the type of place ("gym"), or the generic place name ("Starbucks"), rather than the specific address. You can get suggestions and locations for these places of interest (POIs) using a natural language query. Additionally, you can filter the results to a specific area.
How to use the sample
Choose a type of place in the first field and an area to search within in the second field. Tap the Search button to show the results of the query on the map. Tap on a result pin to show its name and address. If you pan away from the result area, a "Redo search in this area" button will appear. Tap it to query again for the currently viewed area on the map.
How it works
- Create a
LocatorTask
using a URL to a locator service. - Find the location for an address (or city name) to build an envelope to search within:
- Create
GeocodeParameters
. - Add return fields to the parameters'
ResultAttributeNames
collection. Only add a single "*" option to return all fields. - Call
locatorTask.GeocodeAsync(locationQueryString, geocodeParameters)
to get a list ofGeocodeResult
s. - Use the
DisplayLocation
from one of the results to build anEnvelope
to search within.
- Create
- Get place of interest (POI) suggestions based on a place name query:
- Create
SuggestParameters
. - Add "POI" to the parameters'
categories
collection. - Call
locatorTask.SuggestAsync(placeQueryString, suggestParameters)
to get a list ofSuggestResults
. - The
SuggestResult
will have alabel
to display in the search suggestions list.
- Create
- Use one of the suggestions or a user-written query to find the locations of POIs:
- Create
GeocodeParameters
. - Set the parameters'
searchArea
to the envelope. - Call
locatorTask.GeocodeAsync(suggestionLabelOrPlaceQueryString, geocodeParameters)
to get a list ofGeocodeResult
s. - Display the places of interest using the results'
DisplayLocation
s.
- Create
Relevant API
- GeocodeParameters
- GeocodeResult
- LocatorTask
- SuggestParameters
- SuggestResult
Additional information
This sample uses the World Geocoding Service. For more information, see the Geocoding service help topic on the ArcGIS Developer website.
Tags
businesses, geocode, locations, locator, places of interest, POI, point of interest, search, suggestions
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.FindPlace.FindPlace"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Text="Search" />
<Label Grid.Row="1"
Grid.Column="0"
Text="Location" />
<SearchBar x:Name="MySearchBox"
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Focused="MySearchBox_Focused"
IsEnabled="False"
Text="Coffee"
TextChanged="MySearchBox_TextChanged"
Unfocused="MyLocationBox_Unfocused" />
<SearchBar x:Name="MyLocationBox"
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Focused="MySearchBox_Focused"
IsEnabled="False"
Text="Current Location"
TextChanged="MyLocationBox_TextChanged"
Unfocused="MyLocationBox_Unfocused" />
<Button x:Name="MySearchButton"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Clicked="MySearchButton_Clicked"
IsEnabled="False"
Text="Search All" />
<Button x:Name="MySearchRestrictedButton"
Grid.Row="2"
Grid.Column="2"
Clicked="MySearchRestrictedButton_Clicked"
IsEnabled="False"
Text="Search in View" />
<ActivityIndicator x:Name="MyProgressBar"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="3"
IsRunning="True"
IsVisible="False" />
<Grid Grid.Row="4" Grid.ColumnSpan="3">
<ListView x:Name="lstViewSuggestions"
IsVisible="False"
ItemSelected="lstViewSuggestions_ItemSelected">
<!-- Listview appears when there are suggestions -->
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<esriUI:MapView x:Name="MyMapView" />
</Grid>
</Grid>
</ContentPage>