Tutorial: Find place addresses

Learn how to find an address, business, or place with the geocoding service.

You can perform place geocoding with the geocoding service. Place geocoding is the process of searching for addresses for businesses, administrative locations, and geographic features. You can search for the name of a place and/or you can provide categories to filter the results.

In this tutorial, you use the geocode function to find places around the Santa Monica mountains area.

Prerequisites

The ArcGIS API for Python tutorials use Jupyter Notebooks to execute Python code. If you are new to this environment, please see the guide to install the API and use notebooks locally.

Steps

Import modules and log in

  1. Import the arcgis.gis module. This module is the entry point into the GIS and provides the functionality to manage GIS content, users, and groups. Additionally, import the geocode class from the arcgis.geocoding module, which provides types and functions for geocoding, batch geocoding and reverse geocoding.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    
    
  2. Use the GIS class to log in anonymously to ArcGIS Online. Since the results are not stored, you do not need credentials to call the geocoding service.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    
    gis = GIS()
    
    

Find coffee shops near a point

  1. Pass the relevant parameters into the geocode function and get a FeatureSet as the result. Use the location, category, out_fields, and max_location parameters to request the names, addresses, and locations of 25 coffee shops near a point in the Santa Monica Mountains. Set the as_featureset parameter to true to return the results as a feature set so that they can be easily added to a map.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    

Review the results

  1. Use the sdf property of a FeatureSet to convert the feature set into a spatial data frame and render the first two locations.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    geocoded_df = geocoded_features.sdf
    geocoded_df.head(2)
    
    

Map the results

  1. Use the map method of the GIS class to create a map widget.

    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
    
    geocoded_df = geocoded_features.sdf
    geocoded_df.head(2)
    
    map = gis.map()
    map
    
    
  2. Once the map has loaded, use the add method to add the results to the map content and the zoom_to_layer method to update the maps extent to show the geocoded features.

    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
    
    map = gis.map()
    map
    
    from arcgis.map.popups import PopupInfo
    map.content.add(geocoded_features, popup_info=PopupInfo(title="{PlaceName}", description="Address: {Place_addr}"))
    
    map.zoom_to_layer(geocoded_features)
    
    

You should see the results displayed as graphic points on the map.

  1. Optional: Use the export_to_html method to export the current state of the map widget to a static HTML file which can be viewed in any web browser.

    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
    
    from os import path, getcwd
    
    export_dir = path.join(getcwd(), "home")
    if not path.isdir(export_dir):
        os.mkdir(export_dir)
    
    export_path = path.join(export_dir, "find-place-addresses.html")
    
    m.export_to_html(export_path, title="Find place addresses")

What's next?

Learn how to use additional functionality 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.