Find the location for an address.
Use case
A user can input a raw address into your app's search bar and zoom to the address location.
How to use the sample
For simplicity, the sample comes loaded with a set of suggested addresses. Choose an address from the suggestions or submit your own address to show its location on the map in a callout.
How it works
- Create a
LocatorTask
using the URL to a locator service. - Set the
GeocodeParameters
for the locator task and specify the geocode's attributes. - Get the matching results from the
GeocodeResult
usinglocatorTask.GeocodeAsync(addressString, geocodeParameters)
. - Create a
Graphic
with the geocode result's location and store the geocode result's attributes in the graphic's attributes. - Show the graphic in a
GraphicsOverlay
.
Relevant API
- GeocodeParameters
- GeocodeResult
- LocatorTask
Additional information
This sample uses the World Geocoding Service. For more information, see the Geocoding service help topic on the ArcGIS Developer website.
Tags
address, geocode, locator, search
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.FindAddress.FindAddress"
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="*" />
</Grid.RowDefinitions>
<SearchBar x:Name="MySearchBar"
Grid.Row="0"
IsEnabled="false"
Placeholder="Find address"
SearchButtonPressed="Handle_TextChanged" />
<Button x:Name="MySuggestButton"
Grid.Row="1"
Clicked="SuggestionButtonTapped"
IsEnabled="false"
Text="Suggest" />
<esriUI:MapView x:Name="MyMapView" Grid.Row="2" />
</Grid>
</ContentPage>