Find place

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Find places of interest near a location or within a specific area.

Image of find place

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

  1. Create a LocatorTask using a URL to a locator service.
  2. 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 of GeocodeResults.
    • Use the DisplayLocation from one of the results to build an Envelope to search within.
  3. 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 of SuggestResults.
    • The SuggestResult will have a label to display in the search suggestions list.
  4. 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 of GeocodeResults.
    • Display the places of interest using the results' DisplayLocations.

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

FindPlace.xamlFindPlace.xamlFindPlace.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.