Skip to content

Learn how to find places and get details about them with the ArcGIS Places service.

Prerequisites

You need an ArcGIS Location Platform account.

ArcGIS Online and ArcGIS Enterprise accounts are not supported.

Steps

Create a new app

  1. Open a terminal and create a new folder for your project.

    Use dark colors for code blocksCopy
    1
    2
    mkdir find-nearby-places-and-details
    cd find-nearby-places-and-details

  2. Initialize a new Node.js project. This creates a package.json file.

    Use dark colors for code blocksCopy
    1
    npm init
  3. Install the required packages.

    Use dark colors for code blocksCopy
    1
    npm install @esri/arcgis-rest-request @esri/arcgis-rest-places --save

  4. Create a new JavaScript file named index.js.

    Use dark colors for code blocksCopy
    1
    touch index.js

Get an access token

Create a new API key credential with the correct privileges to get an access token.

  1. Go to the Create an API key tutorial and create an API key with the following privilege(s):
    • Privileges:
      • Location services > Places
  2. Copy the API key access token to your clipboard when prompted.

Make a request

  1. Open your index.js file and import the packages.

    index.js
    Use dark colors for code blocks
    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
    
    import { ApiKeyManager } from "@esri/arcgis-rest-request";
    import { findPlacesNearPoint, getPlaceDetails } from "@esri/arcgis-rest-places";
    
    
  2. Paste in your access token.

    index.js
    Use dark colors for code blocks
    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
    
    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);
    
    
  3. Make a request to find places near a specific point and print the results.

    index.js
    Expand
    Use dark colors for code blocks
    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
    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));
    
    });
  4. Using the first response, request detailed information about the first place and print the results.

    index.js
    Expand
    Use dark colors for code blocks
    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
      getPlaceDetails({
        placeId: response.results[0].placeId,
        requestedFields: ["all"],
        authentication
      }).then((response) => {
        console.log(JSON.stringify(response, null, 2));
      });
    
    Expand
  5. Save the file, then run it from the terminal.

    Use dark colors for code blocksCopy
    1
    node index.js

You should now see the results printed in your console.

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
{
  "results": [
    {
      "placeId": "9ba6217093935dfd725ef760b72c21ea",
      "location": {
        "x": -118.243705,
        "y": 34.052143
      },
      "categories": [
        {
          "categoryId": "4bf58dd8d48988d175941735",
          "label": "Gym and Studio"
        }
      ],
      "name": "Second Half Fitness - Personal Training",
Expand

What's next?

Learn how to use additional location services in these tutorials:

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