Learn how to search for businesses, POIs, and geographic locations with the

Place finding is the process of searching for a
In this tutorial, you will use a locator to access the
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or
.
Get an access token
You need an
- Go to the Create an API key tutorial and create an
API key with the followingprivilege(s) :
- Privileges
- Location services > Basemaps
- Location services > Geocoding
- Privileges
- 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.
Update the map
A streets basemap attribute to use the arcgis/navigation basemap layer and change the position of the map to center on Tromso.
-
Update the
basemapattribute fromarcgis/topographictoarcgis/navigationand the center to18.9553,69.6492.29 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map>5 collapsed lines</body></html>
Create a place category selector
You filter place search results by providing a
-
Inside a Calcite Block component, add a Calcite Select component with an id of
places-selectand a Label ofChoose a place type.29 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"></calcite-select></calcite-label></calcite-block></arcgis-map>5 collapsed lines</body></html> -
Create an option component for each category and add it to the Select component.
29 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map>5 collapsed lines</body></html>
Add a script
-
Add a script tag with the type attribute set to module, to the bottom of the body.
26 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module"></script></body>3 collapsed lines</html> -
Using
$arcgis.import, add theGraphicandlocatormodules.The
ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The$arcgis.importglobal function accepts a module path or array of module paths, and returns a promise that resolves with the requested modules. This function can only be used when working with the CDN; otherwise, use the standard import syntax. To learn more about the SDK’s different modules, visit the References page.50 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);</script>5 collapsed lines</body></html>
Define variables for the components
Define variables for the components you will use in the app. You will use these variables to access the components and their properties.
-
Define variables for the
mapandplacesSelectcomponents.50 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");</script>5 collapsed lines</body></html>
Define the service url
You can use a locator to access the
- Define a variable,
locatorUrl, to the URL for theGeocoding service .50 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";</script>5 collapsed lines</body></html>
Search for places
To find locator addressToLocations function. Performing a local search based on a category requires a
-
Create a
findPlacesfunction and calladdressToLocations. Set thelocation,categoriesandoutFieldsproperties.50 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";async function findPlaces(category, point) {const results = await locator.addressToLocations(locatorUrl, {location: point,categories: [category],maxLocations: 25,outFields: ["Place_addr", "PlaceName"],});}</script>5 collapsed lines</body></html> -
Clear the
view of existing pop-ups andgraphics .62 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";async function findPlaces(category, point) {const results = await locator.addressToLocations(locatorUrl, {location: point,categories: [category],maxLocations: 25,outFields: ["Place_addr", "PlaceName"],});viewElement.closePopup();viewElement.graphics.removeAll();}7 collapsed lines</script></body></html> -
Create a
Graphicfor each result returned. Set theattributes,geometry,symbolandpopupTemplateproperties for each. Add each graphic to theviewElement.62 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";async function findPlaces(category, point) {const results = await locator.addressToLocations(locatorUrl, {location: point,categories: [category],maxLocations: 25,outFields: ["Place_addr", "PlaceName"],});viewElement.closePopup();viewElement.graphics.removeAll();results.forEach((result) => {viewElement.graphics.add(new Graphic({attributes: result.attributes,geometry: result.location,symbol: {type: "simple-marker",color: "#000000",size: "12px",outline: {color: "#ffffff",width: "2px",},},popupTemplate: {title: "{PlaceName}",content: "{Place_addr}",},}),);});}7 collapsed lines</script></body></html> -
Call the
findPlacesfunction when the Map loads and each time the Map changes and becomes stationary by listening to the arcgisViewChange event.62 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";viewElement.addEventListener("arcgisViewChange", () => {if (viewElement.stationary) {findPlaces(placesSelectElement.value, viewElement.center);}});41 collapsed linesasync function findPlaces(category, point) {const results = await locator.addressToLocations(locatorUrl, {location: point,categories: [category],maxLocations: 25,outFields: ["Place_addr", "PlaceName"],});viewElement.closePopup();viewElement.graphics.removeAll();results.forEach((result) => {viewElement.graphics.add(new Graphic({attributes: result.attributes,geometry: result.location,symbol: {type: "simple-marker",color: "#000000",size: "12px",outline: {color: "#ffffff",width: "2px",},},popupTemplate: {title: "{PlaceName}",content: "{Place_addr}",},}),);});}</script></body></html> -
Places for parks should be displayed on the map. By dragging the map, you will see new places populate theview .
Add a handler to select a category
Use an event handler to call the findPlaces function when the category is changed.
- Add a
calciteSelectChangeevent listener to listen for category changes.62 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 places</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.0/"></script></head><body><arcgis-map basemap="arcgis/navigation" center="18.9553,69.6492" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><calcite-block expanded slot="top-right"><calcite-label id="places-select-label">Choose a place type<calcite-select id="places-select"><calcite-option value="Parks and Outdoors">Parks and Outdoors</calcite-option><calcite-option value="Coffee shop">Coffee shop</calcite-option><calcite-option value="Gas station">Gas station</calcite-option><calcite-option value="Food">Food</calcite-option><calcite-option value="Hotel">Hotel</calcite-option></calcite-select></calcite-label></calcite-block></arcgis-map><script type="module">const [Graphic, locator] = await $arcgis.import(["@arcgis/core/Graphic","@arcgis/core/rest/locator",]);const placesSelectElement = document.querySelector("#places-select");const viewElement = document.querySelector("arcgis-map");const locatorUrl = "http://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";viewElement.addEventListener("arcgisViewChange", () => {if (viewElement.stationary) {findPlaces(placesSelectElement.value, viewElement.center);}});placesSelectElement.addEventListener("calciteSelectChange", () => {findPlaces(placesSelectElement.value, viewElement.center);});42 collapsed linesasync function findPlaces(category, point) {const results = await locator.addressToLocations(locatorUrl, {location: point,categories: [category],maxLocations: 25,outFields: ["Place_addr", "PlaceName"],});viewElement.closePopup();viewElement.graphics.removeAll();results.forEach((result) => {viewElement.graphics.add(new Graphic({attributes: result.attributes,geometry: result.location,symbol: {type: "simple-marker",color: "#000000",size: "12px",outline: {color: "#ffffff",width: "2px",},},popupTemplate: {title: "{PlaceName}",content: "{Place_addr}",},}),);});}</script></body></html>
Run the app
In CodePen, run your code to display the map.
When you select a category, you should see
What’s next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: