Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Find address

This code sample is available for these platforms:
View Sample on GitHub

Find the location for an address.

Image of find 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

  1. Create a LocatorTask using the URL to a locator service.
  2. Set the GeocodeParameters for the locator task and specify the geocode's attributes.
  3. Get the matching results from the GeocodeResult using locatorTask.GeocodeAsync(addressString, geocodeParameters).
  4. Create a Graphic with the geocode result's location and store the geocode result's attributes in the graphic's attributes.
  5. Show the graphic in a GraphicsOverlay.

Relevant API

  • GeocodeParameters
  • GeocodeResult
  • LocatorTask


address, geocode, locator, search

Sample Code

        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
                <TextBlock Text="Enter an address and tap 🔎 to search."
                           TextAlignment="Center" FontWeight="SemiBold" />
                <AutoSuggestBox x:Name="AutoSuggestBox"
                                ItemsSource="{x:Bind _addresses}"
// Copyright 2017 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.Geocoding;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using Windows.UI.Xaml.Controls;

namespace ArcGISRuntime.UWP.Samples.FindAddress
        name: "Find address",
        category: "Search",
        description: "Find the location for an address.",
        instructions: "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.",
        tags: new[] { "address", "geocode", "locator", "search" })]
    public partial class FindAddress
        // Addresses for suggestion.
        private readonly string[] _addresses =
            "277 N Avenida Caballeros, Palm Springs, CA",
            "380 New York St, Redlands, CA 92373",

        // The LocatorTask provides geocoding services.
        private LocatorTask _geocoder;

        // Service Uri to be provided to the LocatorTask (geocoder).
        private readonly Uri _serviceUri =
            new Uri("");

        public FindAddress()

            // Setup the control references and execute initialization.

        private async void Initialize()
            // Create new Map with basemap.
            Map myMap = new Map(Basemap.CreateImageryWithLabels());

            // Enable tap-for-info pattern on results.
            MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;

            // Assign the map to the MapView.
            MyMapView.Map = myMap;

                // Initialize the LocatorTask with the provided service Uri.
                _geocoder = await LocatorTask.CreateAsync(_serviceUri);

                // Enable UI controls now that the geocoder is ready.
                AutoSuggestBox.IsEnabled = true;
                AutoSuggestBox.IsSuggestionListOpen = true;
            catch (Exception e)
                await new MessageDialog(e.ToString(), "Error").ShowAsync();

        private async void UpdateSearch()
            // Get the text in the search bar.
            string enteredText = AutoSuggestBox.Text;

            // Clear existing marker.

            // Return gracefully if the textbox is empty or the geocoder isn't ready.
            if (String.IsNullOrWhiteSpace(enteredText) || _geocoder == null)

                // Get suggestions based on the input text.
                IReadOnlyList<SuggestResult> suggestions = await _geocoder.SuggestAsync(enteredText);

                // Stop gracefully if there are no suggestions.
                if (suggestions.Count < 1)

                // Get the full address for the first suggestion.
                SuggestResult firstSuggestion = suggestions[0];
                IReadOnlyList<GeocodeResult> addresses = await _geocoder.GeocodeAsync(firstSuggestion.Label);

                // Stop gracefully if the geocoder does not return a result.
                if (addresses.Count < 1)

                // Place a marker on the map - 1. Create the overlay.
                GraphicsOverlay resultOverlay = new GraphicsOverlay();
                // 2. Get the Graphic to display.
                Graphic point = await GraphicForPoint(addresses.First().DisplayLocation);
                // 3. Add the Graphic to the GraphicsOverlay.
                // 4. Add the GraphicsOverlay to the MapView.

                // Update the map extent to show the marker.
                MyMapView.SetViewpoint(new Viewpoint(addresses.First().Extent));
            catch (Exception e)
                await new MessageDialog(e.ToString(), "Error").ShowAsync();

        /// <summary>
        /// Creates and returns a Graphic associated with the given MapPoint.
        /// </summary>
        private async Task<Graphic> GraphicForPoint(MapPoint point)
            // Get current assembly that contains the image.
            Assembly currentAssembly = GetType().GetTypeInfo().Assembly;

            // Get image as a stream from the resources.
            // Picture is defined as EmbeddedResource and DoNotCopy.
            Stream resourceStream = currentAssembly.GetManifestResourceStream(

            // Create new symbol using asynchronous factory method from stream.
            PictureMarkerSymbol pinSymbol = await PictureMarkerSymbol.CreateAsync(resourceStream);
            pinSymbol.Width = 60;
            pinSymbol.Height = 60;
            // The image is a pin; offset the image so that the pinpoint
            //     is on the point rather than the image's true center.
            pinSymbol.LeaderOffsetX = 30;
            pinSymbol.OffsetY = 14;
            return new Graphic(point, pinSymbol);

        /// <summary>
        /// Handle tap event on the map; displays callouts showing the address for a tapped search result.
        /// </summary>
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
                // Search for the graphics underneath the user's tap.
                IReadOnlyList<IdentifyGraphicsOverlayResult> results =
                    await MyMapView.IdentifyGraphicsOverlaysAsync(e.Position, 12, false);

                // Return gracefully if there was no result.
                if (results.Count < 1 || results[0].Graphics.Count < 1)

                // Reverse geocode to get addresses.
                IReadOnlyList<GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(e.Location);

                // Get the first result.
                GeocodeResult address = addresses.First();
                // Use the city and region for the Callout Title.
                string calloutTitle = address.Attributes["City"] + ", " + address.Attributes["Region"];
                // Use the metro area for the Callout Detail.
                string calloutDetail = address.Attributes["MetroArea"].ToString();

                // Define the callout.
                CalloutDefinition calloutBody = new CalloutDefinition(calloutTitle, calloutDetail);

                // Show the callout on the map at the tapped location.
                MyMapView.ShowCalloutAt(e.Location, calloutBody);
            catch (Exception ex)
                await new MessageDialog(ex.ToString(), "Error").ShowAsync();

        private void Search_Submitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)

        private void AutoSuggestBox_OnSuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
            AutoSuggestBox.Text = args.SelectedItem.ToString();