ArcGIS World Geocoding Services
GeocodingA Quick Overview of ArcGIS REST Geocoding API
ArcGIS REST Geocoding API is a geocoding service provided by Esri, which allows developers to perform various geocoding operations. It enables you to find and geocode addresses, place names, and other locations anywhere in the world. In this article, we will walk through the overview of the API, and provide some JavaScript code snippets to get you started quickly.
Getting Started
First, you need to sign up for an ArcGIS developer account in order to access the API. Once you have created an account, you can generate your API credentials to access the endpoints.
The API provides several endpoints that you can use, such as:
- Geocode endpoint: Converts a textual address into a geographic location.
- Reverse geocode endpoint: Converts a geographic location into a textual address.
- Suggest endpoint: Returns a list of suggested addresses and points of interest based on the user's input.
Making a Geocode Request
To make a geocode request, you need to call the geocode endpoint by sending a GET request to the API with the following parameters:
address
: The address you want to geocode.outFields
: The output fields that you want to include in the response.
Here's an example JavaScript code that shows how to make a geocode request using the axios library:
const axios = require('axios');
const url = 'https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates';
const params = {
address: '380 New York St, Redlands, CA',
outFields: 'PlaceName,Match_addr'
};
axios.get(url, { params })
.then(response => console.log(response.data))
.catch(error => console.log(error));
In this example, we use the axios library to send a GET request to the geocode endpoint with the parameters specified in the params
object.
Making a Reverse Geocode Request
To make a reverse geocode request, you need to call the reverse geocode endpoint by sending a GET request to the API with the following parameters:
location
: The geographic coordinates of the location you want to reverse geocode.outFields
: The output fields that you want to include in the response.
Here's an example JavaScript code that shows how to make a reverse geocode request using the axios library:
const axios = require('axios');
const url = 'https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode';
const params = {
location: '-117.19571,34.06148',
outFields: 'City,Region,Country'
};
axios.get(url, { params })
.then(response => console.log(response.data))
.catch(error => console.log(error));
In this example, we use the axios library to send a GET request to the reverse geocode endpoint with the parameters specified in the params
object.
Making a Suggest Request
To make a suggest request, you need to call the suggest endpoint by sending a GET request to the API with the following parameters:
text
: The input text that you want to suggest from.category
: The category to which the suggest search should be restricted.location
: The geographic coordinates within which the suggest search should be conducted.
Here's an example JavaScript code that shows how to make a suggest request using the axios library:
const axios = require('axios');
const url = 'https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest';
const params = {
text: 'time square',
category: 'Populated Place',
location: '-73.985664,40.748817'
};
axios.get(url, { params })
.then(response => console.log(response.data))
.catch(error => console.log(error));
In this example, we use the axios library to send a GET request to the suggest endpoint with the parameters specified in the params
object.
Conclusion
ArcGIS REST Geocoding API is a powerful tool that enables you to perform various geocoding operations. In this short article, we have covered some of the basic concepts of the API, and provided some JavaScript code snippets to help you get started. We hope this will be a useful resource for you in your geocoding journey.