Search for an address

Learn how to find an address or place with a search bar and the geocoding service.

search for an address

Geocoding is the process of converting address or place text into a location. The geocoding service can search for an address or a place and perform reverse geocoding.

In this tutorial, you use a search bar in the user interface to access the Geocoding service and search for addresses and places.

Prerequisites

Before starting this tutorial:

Optionally, you may want to install the ArcGIS Maps SDK for .NET to get access to project templates in Visual Studio (Windows only) and offline copies of the NuGet packages.

Steps

Get an access token

You need an access token to use the location services used in this tutorial.

  1. Go to the Create an API key tutorial to obtain an access token.

  2. Ensure that the following privileges are enabled: Location services > Basemaps > Basemap styles service and Location services > Geocoding.

  3. Copy the access token as it will be used in the next step.

To learn more about other ways to get an access token, go to Types of authentication.

Open a Visual Studio solution

  1. To start the tutorial, complete the Display a map tutorial or download and unzip the solution.

  2. Open the .sln file in Visual Studio.

  3. In the Solution Explorer, click App.xaml.cs.

  4. In the App class, add an override for the OnStartup() function to set the ApiKey property on ArcGISRuntimeEnvironment.

    App.xaml.cs
    Use dark colors for code blocks
    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
        public partial class App : Application
        {
    
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
                Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
            }
    
        }
    }

Update the tutorial name used in the project (optional)

The Visual Studio solution, project, and the namespace for all classes currently use the name DisplayAMap. Follow the steps below if you prefer the name to reflect the current tutorial. These steps are not required, your code will still work if you keep the original name.

Add a graphics overlay

A graphics overlay is a container for graphics. Graphics overlays are typically used to display temporary information, such as the results of an address search operation, and are displayed on top of all other layers. They do not persist when you save the map.

  1. In the Visual Studio > Solution Explorer, double-click MapViewModel.cs to open the file.

  2. Add additional required using statements to your MapViewModel class. Geocoding contains classes used for geocoding (finding geographic locations from an address). The Esri.ArcGISRuntime.UI namespace contains the GraphicsOverlay and Graphic classes and Esri.ArcGISRuntime.Symbology contains the classes that define the symbols for displaying them.

    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    using System;
    using System.Collections.Generic;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Geocoding;
    using Esri.ArcGISRuntime.UI;
    using System.Drawing;
    using System.Linq;
    using System.Threading.Tasks;
    
  3. In the view model, create a new property named GraphicsOverlays. This is a collection of GraphicsOverlay that will store geocode result graphics (address location and label).

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
            private Map? _map;
            public Map? Map
            {
                get { return _map; }
                set
                {
                    _map = value;
                    OnPropertyChanged();
                }
            }
    
            private GraphicsOverlayCollection? _graphicsOverlayCollection;
            public GraphicsOverlayCollection? GraphicsOverlays
            {
                get { return _graphicsOverlayCollection; }
                set
                {
                    _graphicsOverlayCollection = value;
                    OnPropertyChanged();
                }
            }
    
    Expand
  4. At the end of the SetupMap function, add code to create a new GraphicsOverlay, add it to a collection, and assign it to the GraphicsOverlays property.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    
                // Set the view model "Map" property.
                this.Map = map;
    
                // Set the view model "GraphicsOverlays" property.
                GraphicsOverlay overlay = new GraphicsOverlay();
                GraphicsOverlayCollection overlayCollection = new GraphicsOverlayCollection
                {
                    overlay
                };
                this.GraphicsOverlays = overlayCollection;
    
            }
    
    Expand
  5. In the Visual Studio > Solution Explorer, double-click MainWindow.xaml to open the file.

  6. Use data binding to bind the GraphicsOverlays property of the MapViewModel to the MapView control.

    Expand
    Use dark colors for code blocks
    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
            <esri:MapView x:Name="MainMapView"
                          Map="{Binding Map, Source={StaticResource MapViewModel}}"
                          GraphicsOverlays="{Binding GraphicsOverlays, Source={StaticResource MapViewModel}}"/>
    
    Expand

Add a UI for user input

The user will type an address into a text box and then click a button to execute a search. The MapViewModel class contains the logic to execute the search, but the controls are managed by the view.

  1. In the Visual Studio > Solution Explorer, double-click MainWindow.xaml to open the file.

  2. Add a Border above the map view that contains the address search controls.

    Expand
    Use dark colors for code blocks
    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
        <Grid>
    
            <esri:MapView x:Name="MainMapView"
                          Map="{Binding Map, Source={StaticResource MapViewModel}}"
                          GraphicsOverlays="{Binding GraphicsOverlays, Source={StaticResource MapViewModel}}"/>
    
            <Border Background="LightBlue"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    Width="300" Height="60"
                    Margin="0,10">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20"/>
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Search for an address"
                               Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                               TextAlignment="Center" VerticalAlignment="Center"
                               FontWeight="SemiBold" />
                    <TextBox x:Name="AddressTextBox"
                             Grid.Row="1" Grid.Column="0"
                             Margin="5"
                             Text="380 New York Street, Redlands CA"/>
                    <Button x:Name="SearchAddressButton"
                            Grid.Row="1" Grid.Column="1"
                            Margin="5"
                            Content="Search"
                            Click="SearchAddressButton_Click" />
                </Grid>
            </Border>
    
        </Grid>
    
    Expand

Create a function to geocode an address

Geocoding is implemented with a locator, typically created by referencing a geocoding service such as the Geocoding service or, for offline geocoding, by referencing locator data contained in a mobile package. Geocoding parameters can be used to fine-tune the results, such as setting the maximum number of results or requesting additional attributes in the results.

  1. In the Visual Studio > Solution Explorer, double-click MapViewModel.cs to open the file.

  2. Add a new function to search for an address and return its geographic location. The address string and a spatial reference (for output locations) are passed to the function. The function is marked async since it will make asynchronous calls using the await keyword.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                // Set the view model "Map" property.
                this.Map = map;
    
                // Set the view model "GraphicsOverlays" property.
                GraphicsOverlay overlay = new GraphicsOverlay();
                GraphicsOverlayCollection overlayCollection = new GraphicsOverlayCollection
                {
                    overlay
                };
                this.GraphicsOverlays = overlayCollection;
    
            }
    
            public async Task<MapPoint?> SearchAddress(string address, SpatialReference spatialReference)
            {
                MapPoint? addressLocation = null;
    
                try
                {
    
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("Couldn't find address: " + ex.Message);
                }
    
                // Return the location of the geocode result.
                return addressLocation;
            }
    
    Expand
  3. Get the GraphicsOverlay and clear all of its Graphics.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
            public async Task<MapPoint?> SearchAddress(string address, SpatialReference spatialReference)
            {
                MapPoint? addressLocation = null;
    
                try
                {
    
                    // Get the first graphics overlay from the GraphicsOverlays and remove any previous result graphics.
                    GraphicsOverlay? graphicsOverlay = this.GraphicsOverlays?.FirstOrDefault();
                    graphicsOverlay?.Graphics.Clear();
    
    Expand
  4. Create a LocatorTask based on the Geocoding service.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                    // Get the first graphics overlay from the GraphicsOverlays and remove any previous result graphics.
                    GraphicsOverlay? graphicsOverlay = this.GraphicsOverlays?.FirstOrDefault();
                    graphicsOverlay?.Graphics.Clear();
    
                    // Create a locator task.
                    LocatorTask locatorTask = new LocatorTask(new Uri("https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"));
    
    Expand
  5. Create a new GeocodeParameters and define some of its properties.

    • Add the names of attributes to return to the GeocodeParameters.ResultAttributeNames collection. An asterisk (*) indicates all attributes.
    • Set the maximum number of results to be returned with GeocodeParameters.MaxResults. Results are ordered by score, so that the first result has the best match score (ranging from 0 for no match to 100 for the best match).
    • Set the spatial reference for result locations with GeocodeParameters.OutputSpatialReference. By default, the output spatial reference is defined by the geocode service. For optimal performance when displaying the geocode result, you can ensure that returned coordinates match those of the map view by providing the map view's spatial reference.
    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                    // Create a locator task.
                    LocatorTask locatorTask = new LocatorTask(new Uri("https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"));
    
                    // Define geocode parameters: limit the results to one and get all attributes.
                    GeocodeParameters geocodeParameters = new GeocodeParameters();
                    geocodeParameters.ResultAttributeNames.Add("*");
                    geocodeParameters.MaxResults = 1;
                    geocodeParameters.OutputSpatialReference = spatialReference;
    
    Expand
  6. To find the location for the provided address, call LocatorTask.GeocodeAsync, providing the address string and geocodeParameters. The result is a read-only list of GeocodeResult objects. In this tutorial, either one or zero results will be returned, as the maximum results parameter was set to 1.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                    // Define geocode parameters: limit the results to one and get all attributes.
                    GeocodeParameters geocodeParameters = new GeocodeParameters();
                    geocodeParameters.ResultAttributeNames.Add("*");
                    geocodeParameters.MaxResults = 1;
                    geocodeParameters.OutputSpatialReference = spatialReference;
    
                    // Geocode the address string and get the first (only) result.
                    IReadOnlyList<GeocodeResult> results = await locatorTask.GeocodeAsync(address, geocodeParameters);
                    GeocodeResult? geocodeResult = results[0];
                    if(geocodeResult == null) { throw new Exception("No matches found."); }
    
    Expand

Display the result

The geocode result can be displayed by adding a graphic to the map view's graphics overlay.

  1. If a result was found, create two Graphic objects and add them to the graphicsOverlay. Create a graphic to display the geocode result's location, and another to show the geocode result's label text (the located address).

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                    // Geocode the address string and get the first (only) result.
                    IReadOnlyList<GeocodeResult> results = await locatorTask.GeocodeAsync(address, geocodeParameters);
                    GeocodeResult? geocodeResult = results[0];
                    if(geocodeResult == null) { throw new Exception("No matches found."); }
    
                    // Create a graphic to display the result location.
                    SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Square, Color.Blue, 12);
                    Graphic markerGraphic = new Graphic(geocodeResult.DisplayLocation, geocodeResult.Attributes, markerSymbol);
    
                    // Create a graphic to display the result address label.
                    TextSymbol textSymbol = new TextSymbol(geocodeResult.Label, Color.Red, 18, HorizontalAlignment.Center, VerticalAlignment.Bottom);
                    Graphic textGraphic = new Graphic(geocodeResult.DisplayLocation, textSymbol);
    
                    // Add the location and label graphics to the graphics overlay.
                    graphicsOverlay?.Graphics.Add(markerGraphic);
                    graphicsOverlay?.Graphics.Add(textGraphic);
    
    Expand
  2. Set addressLocation with the location of the result to return it from the function. The calling function will use this MapPoint to pan the display to the result location.

    Expand
    Use dark colors for code blocks
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
                    // Add the location and label graphics to the graphics overlay.
                    graphicsOverlay?.Graphics.Add(markerGraphic);
                    graphicsOverlay?.Graphics.Add(textGraphic);
    
                    // Set the address location to return from the function.
                    addressLocation = geocodeResult?.DisplayLocation;
    
    Expand

Search for an address when the button is clicked

  1. In the Visual Studio > Solution Explorer, double-click MainWindow.xaml.cs to open the file.

  2. Add a handler for the SearchAddressButton click event.

    Expand
    Use dark colors for code blocks
    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
            public MainWindow()
            {
                InitializeComponent();
    
                // Create a point centered on the Santa Monica mountains in Southern California.
                // Longitude=118.805 degrees West, Latitude=34.027 degrees North
                var mapCenterPoint = new Esri.ArcGISRuntime.Geometry.MapPoint(-118.805, 34.027, Esri.ArcGISRuntime.Geometry.SpatialReferences.Wgs84);
    
                // Create a viewpoint for the initial display of the map.
                // Use the point defined above and a scale of 1:100,000
                MainMapView.SetViewpoint(new Esri.ArcGISRuntime.Mapping.Viewpoint(mapCenterPoint, 100_000));
            }
    
            private async void SearchAddressButton_Click(object sender, RoutedEventArgs e)
            {
    
            }
    
    Expand
  3. Find MapViewModel from the page resources.

    Expand
    Use dark colors for code blocks
    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
            private async void SearchAddressButton_Click(object sender, RoutedEventArgs e)
            {
    
                // Get the MapViewModel from the page (defined as a static resource).
                var viewModel = (MapViewModel)FindResource("MapViewModel");
                if(viewModel == null) { return; }
    
            }
    
    Expand
  4. Call the SearchAddress function on the MapViewModel and store the returned MapPoint.

    Expand
    Use dark colors for code blocks
    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
            private async void SearchAddressButton_Click(object sender, RoutedEventArgs e)
            {
    
                // Get the MapViewModel from the page (defined as a static resource).
                var viewModel = (MapViewModel)FindResource("MapViewModel");
                if(viewModel == null) { return; }
    
                // Call SearchAddress on the view model, pass the address text and the map view's spatial reference.
                var spatialReference = MainMapView.SpatialReference;
                if(spatialReference== null) { return; }
                MapPoint? addressPoint = await viewModel.SearchAddress(AddressTextBox.Text, spatialReference);
    
            }
    
    Expand
  5. If a map point is returned, center the MapView on the address result.

    Expand
    Use dark colors for code blocks
    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
            private async void SearchAddressButton_Click(object sender, RoutedEventArgs e)
            {
    
                // Get the MapViewModel from the page (defined as a static resource).
                var viewModel = (MapViewModel)FindResource("MapViewModel");
                if(viewModel == null) { return; }
    
                // Call SearchAddress on the view model, pass the address text and the map view's spatial reference.
                var spatialReference = MainMapView.SpatialReference;
                if(spatialReference== null) { return; }
                MapPoint? addressPoint = await viewModel.SearchAddress(AddressTextBox.Text, spatialReference);
    
                // If a result was found, center the display on it.
                if (addressPoint != null)
                {
                    await MainMapView.SetViewpointCenterAsync(addressPoint);
                }
    
            }
    
    Expand
  6. Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app.

You should see the address search controls at the top center of the map. To search for an address, enter an address and then click Search. If a result is found, the map will pan to the location and label a graphic for that address.

What's next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials:

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