Learn how to find places and get details about them with the ArcGIS Places service.
Prerequisites
You need an ArcGIS Location Platform account.
ArcGIS Online and ArcGIS Enterprise accounts are not supported.
Steps
Create a new app
-
Open a terminal and create a new folder for your project.
Use dark colors for code blocks Copy mkdir find-nearby-places-and-details cd find-nearby-places-and-details -
Initialize a new Node.js project. This creates a
package.jsonfile.Use dark colors for code blocks Copy npm init -
Install the required packages.
Use dark colors for code blocks Copy npm install @esri/arcgis-rest-request @esri/arcgis-rest-places --save -
Create a new JavaScript file named
index.js.Use dark colors for code blocks Copy touch index.js
Get an access token
Create a new API key credential with the correct privileges to get an access token.
- Go to the Create an API key tutorial and create an API key with the following privilege(s):
- Privileges:
- Location services > Places
- Privileges:
- Copy the API key access token to your clipboard when prompted.
Make a request
-
Open your
index.jsfile and import the packages.index.jsUse dark colors for code blocks import { ApiKeyManager } from "@esri/arcgis-rest-request"; import { findPlacesNearPoint, getPlaceDetails } from "@esri/arcgis-rest-places"; -
Paste in your access token.
index.jsUse dark colors for code blocks import { ApiKeyManager } from "@esri/arcgis-rest-request"; import { findPlacesNearPoint, getPlaceDetails } from "@esri/arcgis-rest-places"; const accessToken = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(accessToken); -
Make a request to find places near a specific point and print the results.
index.jsUse dark colors for code blocks findPlacesNearPoint({ x: -118.2437, // Downtown Los Angeles, CA y: 34.0522, categoryIds: ["4f4528bc4b90abdf24c9de85"], // Sports and Recreation category radius: 750, authentication }).then((response) => { console.log(JSON.stringify(response, null, 2)); }); -
Using the first response, request detailed information about the first place and print the results.
index.jsUse dark colors for code blocks getPlaceDetails({ placeId: response.results[0].placeId, requestedFields: ["all"], authentication }).then((response) => { console.log(JSON.stringify(response, null, 2)); }); -
Save the file, then run it from the terminal.
Use dark colors for code blocks Copy node index.js
You should now see the results printed in your console.
{
"results": [
{
"placeId": "9ba6217093935dfd725ef760b72c21ea",
"location": {
"x": -118.243705,
"y": 34.052143
},
"categories": [
{
"categoryId": "4bf58dd8d48988d175941735",
"label": "Gym and Studio"
}
],
"name": "Second Half Fitness - Personal Training",
What's next?
Learn how to use additional location services in these tutorials: