Introduction to Places

Places, also known as points of interest (POIs), are businesses and geographic locations that you can discover around the world. To find places you use the places service. The service allows you to search for places near a location or within a bounding box. To find specific types of places you can use over 1000 place categories and your own text to refine the search results. Places also contain valuable details, also known as attributes, such as name, category, street address, marketing district, contact information, website, social links, hours of operation, price ratings, and user ratings.

How to find places of interest

To find points of interest, and return details about them, you make a request to the places service. The easiest way to access the service is to use the places package from ArcGIS REST JS.

The general steps are as follows:

  1. Reference the places and request packages from ArcGIS REST JS.

  2. Set an API key that is scoped to access the places service.

  3. Choose a type of search. You can search for places within a bounding box or for places near a location.

  4. To filter and return the best results, provide a list of categories and/or keywords for the search. Go to the places category browser for a full list of categories.

  5. Submit the request to the service.

  6. To request additional attributes for each place, use the placeId and set the requestedFields parameter to specify the fields you want with the getPlaceDetails operation.

Examples

Find places in a bounding box

In this example, you use the findPlacesWithinExtent operation to find places within a bounding box based on a specific keyword.

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
    const bounds = map.getBounds();
    const topRight = bounds.getNorthEast();
    const bottomLeft = bounds.getSouthWest();

    arcgisRest.findPlacesWithinExtent({
        xmin: bottomLeft.lng,
        ymin: bottomLeft.lat,
        xmax: topRight.lng,
        ymax: topRight.lat,
        searchText: "Night Clubs", // Search for "Night Clubs"
        authentication
    })
    .then((response) => {
        response.results.forEach((result) => {
            const marker = new maplibregl.Marker()
            .setLngLat([result.location.x, result.location.y])
            .addTo(map);
        });
    });

Find nearby places

In this example, you use the findPlacesNearPoint operation to find places based on a specific category within a 750 meter search radius of a location.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
    arcgisRest.findPlacesNearPoint({
        x: userLocation.lng,
        y: userLocation.lat,
        categoryIds:["16000"], // Arts and Outdoors category
        radius: 750, // default units in meters
        authentication
    })
    .then((response)=>{
        response.results.forEach((result) => {
            addResult(result);
        });
    });

Paginate search results

If your requests returns more than ten results, you can page through them using the URL in the links attribute. The maximum number of places that can be returned in total is 200.

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
 async function showPlaces() {
        processing = true;

        let lastResponse = await arcgisRest.findPlacesNearPoint({
          x: activeLocation.lng,
          y: activeLocation.lat,
          categoryIds: activeCategory.categoryIds,
          searchText: activeSearchText,
          radius: activeRadius,
          pageSize: pageSize,
          authentication,
        });

        lastResponse.results.forEach(result => {
          addMarker(result);
        });

        if (!lastResponse.nextPage) {
          processing = false;
        } else {
          while (lastResponse.nextPage && processing) {
            try {
              lastResponse = await lastResponse.nextPage() ;
              lastResponse.results.forEach(result => {
                addMarker(result)
              })
            } catch(error) {
              console.log(error);
              break;
            } finally {}
          };
          processing = false;
        };
      }

Get place details

In this example, you use the getPlace operation with a valid place ID returned from performing a nearby or bounding box search. Once you have a placeId, you need to define a list of the fields you would like with the requestedFields parameter. For example, [name,address:streetAddress, contactInfo:telephone].

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
    arcgisRest.getPlace({
        placeId: id,
        requestedFields: ["name","address:streetAddress", "contactInfo:telephone"],
        authentication
    })
    .then((response) => {
        console.log(response.placeDetails.name);
        console.log(response.placeDetails.address.streetAddress);
        console.log(response.placeDetails.contactInfo.telephone);
    });

Tutorials

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