Find nearby places and details

Explore in the sandbox

This sample demonstrates how to use esri/rest/places to find nearby places and details.

Find places within a search distance of a geographic point, and find more information about specific places. Places, also known as points of interest (POIs), are businesses and geographic locations that one can discover around the world. Places also contain attributes such as name, category, street address, contact information, and more. With the places service one can build powerful applications to help people discover, locate, and learn more about places around them. The places service can search for businesses, points of interest (POI), and popular geographic features near a location or within a bounding box.

A nearby search finds places within a given radius of a location using the places service. The location typically represents a point on a map or the geolocation of a device. To perform a nearby search, use esri/rest/places. With the results of the search, one can make another request to the service and return place attributes including the name, categories, ratings, and store hours.

Instructions

To run this sample, select a category of interest from the top left panel. Then click on the map to see up to 10 features displayed on the map, symbolized based on category. These features are also listed in the left panel. Changing the category after clicking on the map will re-run the place search in the same location with the updated category value. Clicking on a feature in the left panel will open a popup on the associated feature on the map, and highlight that feature using it's LayerView. Clicking on another feature will close the previous feature's popup and remove the highlight, then open the popup and highlight the new feature.

How it works

The places service requires a token for authentication. This sample uses an API Key to authenticate. You can either replace it with your own API Key, or remove it and log in once prompted. Alternatively, you can use another authentication method to access the places service.

When the map is clicked, an event listener captures the user's click location and converts the screen coordinates to longitude and latitude, then passes those values to the showPlaces() function.

Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343  // View on-click event to capture places search location  view.on("click", (event) => {  bufferLayer.removeAll(); // Remove graphics from GraphicsLayer of previous buffer  placesLayer.removeAll(); // Remove graphics from GraphicsLayer of previous places search  clickPoint = {};  clickPoint.type = "point";  // Convert clicked screen location to longitude and latitude  clickPoint.longitude = Math.round(event.mapPoint.longitude * 1000) / 1000;  clickPoint.latitude = Math.round(event.mapPoint.latitude * 1000) / 1000;  // Pass point to the showPlaces() function  clickPoint && showPlaces(clickPoint);  }); 

Pass the user's click location with a 500m search radius, place category, and icon to places service using the PlacesQueryParameters. Pass the results, as PlacesQueryResult to the tabulatePlaces() function.

Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343  // Pass search area, categories, and API Key to places service  chicagoPlacesQueryParameters = new PlacesQueryParameters({  categoryIds: [activeCategory],  radius: 500, // set radius to 500 meters  point: clickPoint,  icon: "png",  });  // The results variable represents the PlacesQueryResult  const results = await places.queryPlacesNearPoint(chicagoPlacesQueryParameters);  // Pass the PlacesQueryResult to the tabulatePlaces() function  tabulatePlaces(results); 

Process the individual PlaceResults from the array of results from the PlacesQueryResult to the addResult() function.

Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343  // Investigate the individual PlaceResults from the array of results  // from the PlacesQueryResult and process them  function tabulatePlaces(results) {  resultPanel.innerHTML = "";  if (infoPanel) infoPanel.remove();  results.results.forEach((placeResult) => {  // Pass each result to the addResult() function  addResult(placeResult);  });  }  // Visualize the places on the map based on category  // and list them on the left panel with more details  async function addResult(place) {  const placePoint = {  type: "point",  y: place.location.y,  x: place.location.x,  };  const placeGraphic = new Graphic({  geometry: placePoint,  symbol: {  type: "picture-marker",  url: place.icon.url, // use icon from places service  width: 15,  height: 15,  },  }); 

Once each place is represented by the appropriate symbol for it's category, add the graphic to the GraphicsLayer, and use FetchPlaceParameters to fetch more details about each place based on the place ID with all possible fields.

Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343  // Add each graphic to the GraphicsLayer  placesLayer.graphics.add(placeGraphic);  // Fetch more details about each place based  // on the place ID with all possible fields  const fetchPlaceParameters = new FetchPlaceParameters({  placeId: place.placeId,  requestedFields: ["all"],  }); 

Now that the features are symbolized on the map, and the feature details are listed in the panel on the left, we listen for when a feature on the left is selected, and then open the popup for the relevant feature on the map and highlight the feature using the GraphicsLayerView.highlight() method. Then pass the FetchPlaceParameters and the feature location to the getDetails() function, which calls the fetchPlace() method to get additional details on the place for display in the left panel.

Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343  // If a place in the left panel is clicked  // then open the feature's popup  infoDiv.addEventListener("click", async () => {  view.openPopup({  location: placePoint,  title: place.name,  content: "See panel for more details",  });  // Highlight the selected place feature  const layerView = await view.whenLayerView(placesLayer);  highlightSelect = layerView.highlight(placeGraphic);  // Move the view to center on the selected place feature  view.goTo(placeGraphic);  // Pass the FetchPlaceParameters and the location of the  // selected place feature to the getDetails() function  getDetails(fetchPlaceParameters, placePoint);  });  resultPanel.appendChild(infoDiv);  }   // Get place details and display in the left panel  async function getDetails(fetchPlaceParameters, placePoint) {  // Get place details  const result = await places.fetchPlace(fetchPlaceParameters);  const placeDetails = result.placeDetails;  // Move the view to center on the selected place feature  view.goTo(placePoint); 

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.