You can use the arcgis-rest-places package to access the ArcGIS Places service.
Steps
-
Install and reference the
arcgis-rest-placesandarcgis-rest-requestpackages. - Set an access token to authenticate the request.
- Define parameters to pass to the service.
- Call the service and handle the results.
Nearby search
You can search for nearby places such as cafes, hospitals, or parks, by searching within a distance from a point or device location. You can also filter search results by using place categories.
Find nearby places and details
Learn how to find places within a radius and return details about them with the find and get methods.
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);
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));
getPlaceDetails({
placeId: response.results[0].placeId,
requestedFields: ["all"],
authentication
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});
});Bounding box search
Place finding is the process of discovering businesses and geographic locations, also known as points of interest (POIs).
Find places in a bounding box
Learn how to find places within an extent with the find method.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { findPlacesWithinExtent } from "@esri/arcgis-rest-places";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
findPlacesWithinExtent({
xmin: -115.2, // Coordinates around the Las Vegas Strip
ymin: 36.09,
xmax: -115.1,
ymax: 36.161,
searchText: "Night Clubs", // Search for "Night Clubs"
authentication,
f: "geojson"
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});