Search for an address

Learn how to find an address or place with a search widget and the Geocoding service.

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. Use the Search widget to access the Geocoding service and perform interactive searches.

In this tutorial, you use the Search widget to search for addresses and places.

Prerequisites

You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.

Steps

Create a new pen

  1. To get started, either complete the Display a map tutorial or .

Set the API key

To access ArcGIS services, you need an API key.

  1. Go to your dashboard to get an API key.

  2. In CodePen, set the apiKey to your key, so it can be used to access basemap layer and location services.

        
    Change line
    1
    2
    3
    4
    esriConfig.apiKey = "YOUR_API_KEY";
    const map = new Map({
      basemap: "arcgis-topographic" // Basemap layer service
    });
    

Add modules

  1. In the require statement, add the Search module.

    The ArcGIS API for JavaScript uses AMD modules. The require function is used to load modules so they can be used in the main function. It's important to keep the module references and function parameters in the same order.

                                                          
    Add line.Change line
    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
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Search for an address</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.21/"></script>
    
      <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/widgets/Search"
    
      ], function(esriConfig,Map, MapView, Search) {
      esriConfig.apiKey = "YOUR_API_KEY";
      const map = new Map({
          basemap: "arcgis-navigation"
      const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.3321,47.6062],
          zoom: 12
      const search = new Search({  //Add Search widget
          view: view
        view.ui.add(search, "top-right"); //Add to the map
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Update the map

A streets basemap layer is typically used in geocoding applications. Update the basemap property to use the arcgis-navigation basemap layer and change the position of the map to center on Seattle.

  1. Update the basemap property from arcgis-topographic to arcgis-navigation.

                                                          
    Change line
    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
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Search for an address</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.21/"></script>
    
      <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Search"
      ], function(esriConfig,Map, MapView, Search) {
      esriConfig.apiKey = "YOUR_API_KEY";
    
      const map = new Map({
          basemap: "arcgis-navigation"
        });
      const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.3321,47.6062],
          zoom: 12
      const search = new Search({  //Add Search widget
          view: view
        view.ui.add(search, "top-right"); //Add to the map
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Update the center property to [-122.3321, 47.6062] and set the zoom property to 12 to center on Seattle.

                                                          
    Change lineChange line
    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
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Search for an address</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.21/"></script>
    
      <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Search"
      ], function(esriConfig,Map, MapView, Search) {
      esriConfig.apiKey = "YOUR_API_KEY";
      const map = new Map({
          basemap: "arcgis-navigation"
      const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.3321,47.6062],
          zoom: 12
        });
    
      const search = new Search({  //Add Search widget
          view: view
        view.ui.add(search, "top-right"); //Add to the map
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Add a Search widget

The Search widget is a visible control that allows you to interactively search for addresses and places. It provides suggestions as you type and allows you to select a result. When you select a result, it zooms to a location and displays a pop-up with the address information. By default, the widget uses a locator and source that accesses the Geocoding service.

  1. Create a Search widget. Set the view property to view.

                                                          
    Add line.Add line.Add line.
    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
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Search for an address</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.21/"></script>
    
      <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Search"
      ], function(esriConfig,Map, MapView, Search) {
      esriConfig.apiKey = "YOUR_API_KEY";
      const map = new Map({
          basemap: "arcgis-navigation"
      const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.3321,47.6062],
          zoom: 12
        });
    
      const search = new Search({  //Add Search widget
          view: view
        });
        view.ui.add(search, "top-right"); //Add to the map
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Add the widget to the top right corner of the view. Learn more about adding UI components to the view in DefaultUI.

                                                          
    Add line.
    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
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Search for an address</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.21/"></script>
    
      <script>
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/widgets/Search"
      ], function(esriConfig,Map, MapView, Search) {
      esriConfig.apiKey = "YOUR_API_KEY";
      const map = new Map({
          basemap: "arcgis-navigation"
      const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.3321,47.6062],
          zoom: 12
      const search = new Search({  //Add Search widget
          view: view
        });
    
        view.ui.add(search, "top-right"); //Add to the map
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Run the app

In CodePen, run your code to display the map.

Try searching for the following locations:

    
1
2
3
4
- `Seattle`
- `Space Needle`
- `Hollywood Blvd`
- `34.13419, -118.29636`

The map should display a Search widget and that allows you to interactively search for addresses and places.

What's next?

Learn how to use additional API features and ArcGIS services 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.