Tutorial: Search for an address

Learn how to find an address the geocoding service.

Python mapping widget showing geocoded points

Geocoding is the process of converting address or place text into a location. The geocoding service provides address and place geocoding as well as reverse geocoding.

In this tutorial, you use the geocode class to find addresses in Los Angeles, CA.

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 and reverse_geocode classes from the arcgis.geocoding module. Additionally, import the Point class from the arcgis.geometry module.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode, reverse_geocode
    from arcgis.geometry import Point
    from arcgis.geometry import Feature
    
    
    
  2. Log into ArcGIS Online as an anonymous user. Simple geocoding and reverse geocoding do not require credits, hence you need not log in using your credentials.

    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
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode, reverse_geocode
    from arcgis.geometry import Point
    from arcgis.geometry import Feature
    
    
    portal = GIS()
    
    

Find an address

  1. Search for an address by passing in the string "1000 Vin Scully Ave, Los Angeles, CA" as the address parameter of the geocode function. The geocode() function is versatile and accepts a number of relevant parameters. Refer to Finding points of interest to learn more.

    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
    
    portal = GIS()
    
    geocode_results = geocode(address="1000 Vin Scully Ave, Los Angeles, CA", as_featureset=True)
    geocode_results
    
    

Reverse geocode a coordinate

  1. Construct a Point geometry object for the following latitude and longitude: 34.13419,-118.29636. The coordinates specified here are in latitude, longitude which correspond to the spatial reference GCS_WGS_1984. For a complete list of supported IDs and their corresponding definition strings, see: Spatial references.

    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
    
    geocode_results = geocode(address="1000 Vin Scully Ave, Los Angeles, CA", as_featureset=True)
    geocode_results
    
    location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}}
    unknown_pt = Point(location)
    
    
  2. Use the reverse_geocode function to find the address from a point location. Create a Feature from the returned dict and it to the geocoded_results FeatureSet.

    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
    
    location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}}
    unknown_pt = Point(location)
    
    reverse_result = reverse_geocode(location=unknown_pt)
    reverse_result
    
    reverse_result_feature = Feature(geometry=reverse_result["location"],attributes=reverse_result["address"])
    
    geocode_results.features.append(reverse_result_feature)
    geocode_results
    
    
    

Create a map

  1. Create an instance of the map widget and set the initial extent by passing in a place name string of Los Angeles, CA.

    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
    
    reverse_result = reverse_geocode(location=unknown_pt)
    reverse_result
    
    reverse_result_feature = Feature(geometry=reverse_result["location"],attributes=reverse_result["address"])
    
    geocode_results.features.append(reverse_result_feature)
    geocode_results
    
    
    map = portal.map("Los Angeles, CA")
    map
    
    

Display the results.

  1. Use the add method to display the results on the map. Since you specified the as_featureset=True optional parameter while geocoding, you received the result as a FeatureSet object instead of a dictionary. FeatureSet objects can be easily visualized on the map by passing to the add method.

    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
    
    map = portal.map("Los Angeles, CA")
    map
    
    from arcgis.map.popups import PopupInfo
    map.content.add(geocode_results, popup_info=PopupInfo(title="{Addr_type}", description="Address: {LongLabel}"))

Try geocoding using the following addresses.

  • Single line address: 380 New York St, Redlands, CA
  • Administrative place name: New York City
  • Zipcode: 66952

You should see the results of both the geocoded address and reverse geocoded point displayed as graphics on the map.

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.