Learn how to find an address near a location with the Geocoding service.
Reverse geocoding is the process of converting a location to an address or place. To reverse geocode, you use the Geocoding service and the reverseGeocode operation. This operation requires an initial location and returns an address with attributes such as place name and location. To simplify accessing the Geocoding service, you use the locator module.
In this tutorial, you use the locator to reverse geocode and find the closest address to your clicked location on the map.
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.
The ArcGIS Maps SDK for JavaScript is available as AMD modules and ES modules, but this tutorial is based on AMD. The AMD require function uses references to determine which modules will be loaded – for example, you can specify "esri/Map" for loading the Map module. After the modules are loaded, they are passed as parameters (e.g. Map) to the callback function where they can be used in your application. It is important to keep the module references and callback parameters in the same order. For more information on the different types of modules, visit the Introduction to Tooling guide topic.
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 Quito.
Update the basemap property from arcgis-topographic to arcgis-navigation.
Use a handler to capture a click location on the map and then call the Geocoding service. The service returns an address if an address is found, or an error if it cannot find a result. Display the results in a pop-up with the latitude, longitude, and address.
In the main function, add a click handler to the view. Create params and set the location to evt.mapPoint.