Learn how to find elevation values for points along a path in New Zealand's South Island.
Prerequisites
You need an ArcGIS Location Platform account.
ArcGIS Online and ArcGIS Enterprise accounts are not supported.
Steps
Create a new app
-
Open a terminal and create a new folder for your project.
Use dark colors for code blocks Copy mkdir find-the-elevations-of-multiple-points cd find-the-elevations-of-multiple-points -
Initialize a new Node.js project. This creates a
package.jsonfile.Use dark colors for code blocks Copy npm init -
Install the required packages.
Use dark colors for code blocks Copy npm install @esri/arcgis-rest-request @esri/arcgis-rest-elevation --save -
Create a new JavaScript file named
index.js.Use dark colors for code blocks Copy touch index.js
Get an access token
Create a new API key credential with the correct privileges to get an access token.
- Go to the Create an API key tutorial and create an API key with the following privilege(s):
- Privileges:
- Location services > Elevation service
- Privileges:
- Copy the API key access token to your clipboard when prompted.
Make a request
-
Open your
index.jsfile and import the packages.index.jsUse dark colors for code blocks import { ApiKeyManager } from "@esri/arcgis-rest-request"; import { findElevationAtManyPoints } from "@esri/arcgis-rest-elevation"; -
Paste in your access token.
index.jsUse dark colors for code blocks import { ApiKeyManager } from "@esri/arcgis-rest-request"; import { findElevationAtManyPoints } from "@esri/arcgis-rest-elevation"; const accessToken = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(accessToken); -
Make a request to find the elevations of multiple points along New Zealand's South Island and print the results.
index.jsUse dark colors for code blocks import { ApiKeyManager } from "@esri/arcgis-rest-request"; import { findElevationAtManyPoints } from "@esri/arcgis-rest-elevation"; const accessToken = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(accessToken); findElevationAtManyPoints({ coordinates: [ [1.2783, 51.1102], // Dover, UK [1.3507, 51.0883], [1.4206, 51.0524], [1.4939, 51.0162], [1.5978, 50.9827], [1.7302, 50.9387] // Calais, France ], authentication }).then((response) => { console.log(JSON.stringify(response, null, 2)); }); -
Save the file, then run it from the terminal.
Use dark colors for code blocks Copy node index.js
You should now see the results printed in your console.
{
"result": {
"points": [
{
"x": 1.2783,
"y": 51.1102,
"z": 85.4,
"spatialReference": {
"wkid": 4326,
"vcsWkid": 105700
}
},
{
"x": 1.3507,
"y": 51.0883,
What's next?
Learn how to use additional location services in these tutorials: