Tutorial: Search for an address

Learn how to find an address the geocoding service.

Python mapping widget displaying a map of Malibu, CA

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 an address 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

from arcgis.gis import GIS
from arcgis.geocoding import geocode, reverse_geocode
from arcgis.geometry import Point


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

Find an address

  1. Search for an address by passing in the string "Hollywood sign" 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
    
    gis = GIS()
    
    geocode_result = geocode(address="Hollywood sign", as_featureset=True)
    geocode_result
    
    

Create a map

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

    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
    
    geocode_result = geocode(address="Hollywood sign", as_featureset=True)
    geocode_result
    
    m = gis.map("Los Angeles, CA", zoomlevel=11)
    m
    
    

Display the results.

  1. Use the draw 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 drawn on the map widget by passing them to the draw() 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
    
    geocode_result = geocode(address="Hollywood sign", as_featureset=True)
    geocode_result
    
    m = gis.map("Los Angeles, CA", zoomlevel=11)
    m
    
    m.draw(geocode_result)
    
    
  2. Use the clear_graphics() method to remove the previous result graphics.

    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
    
    m = gis.map("Los Angeles, CA", zoomlevel=11)
    m
    
    m.draw(geocode_result)
    
    m.clear_graphics()
    
    

    Try geocoding using the following addresses.

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

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
    
    m.clear_graphics()
    
    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.

    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
    
    location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}}
    unknown_pt = Point(location)
    
    address = reverse_geocode(location=unknown_pt)
    address
    
    

Display the results

  1. Use the draw method to add the results of the reverse_geocode to the 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

location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}}
unknown_pt = Point(location)

address = reverse_geocode(location=unknown_pt)
address

m.draw(address)

You should see the results of the reverse geocode displayed as a point graphic 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.