Learn how to find places around a location
See the place and popup on the map, and inspect the console for more places information.
A nearby search finds places
Import the places module. With the results of the search, you can make another request to the service and return place attributes including the name, categories, ratings, and store hours.
In this tutorial, you will use ArcGIS Maps SDK for JavaScript to perform a nearby search to find points of interest and return all available attributes associated with a place.
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or
.
Get an access token
You need an access token
Go to the Create an API key tutorial and create an API key
An API key is a long-lived access token created using API key credentials. They are valid for up to one year and are typically embedded directly into client applications. with the following privilege(s)Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. :- Privileges
Location services > Basemaps
Location services > Places
In CodePen, set the
apiKeyproperty on the globalesriConfigvariable to your access token.var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};
To learn about other ways to get an access token, go to Types of authentication.
Add script
- In a new 38 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Find nearby places and details</title><style>html,body {height: 100%;margin: 0;}</style><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.1/"></script></head><body><calcite-shell><arcgis-map center="-118.46651, 33.98621" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map></calcite-shell><script type="module">const [Circle, Graphic, GraphicsLayer, Map, places, FetchPlaceParameters, PlacesQueryParameters] =await $arcgis.import(["@arcgis/core/geometry/Circle.js","@arcgis/core/Graphic.js","@arcgis/core/layers/GraphicsLayer.js","@arcgis/core/Map.js","@arcgis/core/rest/places.js","@arcgis/core/rest/support/FetchPlaceParameters.js","@arcgis/core/rest/support/PlacesQueryParameters.js",]);</script>3 collapsed lines</body></html>