Overview

You will learn: how to search for coffee shops, gas stations, restaurants, and other places around a location.

The ArcGIS World Geocoding Service can find addresses and places, convert addresses to coordinates, and perform batch geocoding. If you want to add POIs (Points of Interest) to your analytical workflows, you can search for places such as coffee shops, gas stations, or restaurants. To find places, use the geocode function and pass in a location and search category (e.g. "Coffee Shop").

You can then visualize the results on a map, manipulate the results in a Pandas Dataframe, and more.

To learn more about the capabilities of the geocoding service, visit the REST API documentation.

In this tutorial, you will create a script to search and display different places around the Santa Monica Mountains area.

Before you begin

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

Create a new notebook

  1. Go to Esri Juptyter Notebooks and click New > Python 3 to create a new notebook.

    In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.

  1. Add the following code to model a GIS portal and import the geocode function from the ArcGIS API for Python.

    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
  2. Create an anonymous connection to ArcGIS Online.

    gis = GIS()
    
  3. Pass the relevant parameters into the geocode function and get a FeatureSet as the result.

    geocode_fs = geocode(address=None,
                        location=[-118.71511, 34.09042],
                        category="Coffee shop",
                        out_fields="Place_addr, PlaceName",
                        max_locations=25,
                        as_featureset=True)
    
  4. Convert the results to a Pandas Dataframe by calling the sdf property of a FeatureSet and show the first two locations.

    geocode_df = geocode_fs.sdf
    geocode_df.head(2)
    
  5. Create a map to display the results.

    m = gis.map()
    
    # Wait for the map to load before setting the center and zoom level
    m.center = [34.09042, -118.71511]           # `[latitude, longitude]`
    m.zoom = 11
    
  6. Once the map has loaded, draw the results.

    m.draw(geocode_fs)
    

Congratulations, you're done!

Your notebook should look something like this.

If you would like to translate a point to an address, or vis versa, please see the Search for an address tutorial.

Challenge

Explore more categories

The World Geocoding service can find many different types of places. Explore the Level 1, Level 2, and Level 3 Categories and pass them to the geocode function to search for additional places that you are interested in. Note that you can join categories to search for more than one at a time. For example:

category = "Coffee shop, Gas station, Food, Hotel"