Routing is the process of finding the best path from an origin to a destination in a street network.
You can use thearcgis-rest-routing package to access the ArcGIS Routing service.
Steps
-
Install and reference the
arcgis-rest-routingandarcgis-rest-requestpackages. - Set an access token to authenticate the request.
- Define parameters to pass to the service.
- Call the service and handle the results.
Routes and directions
Routing finds the best path between locations and considers factors such as speed limits, road conditions, stops, time of day, and traffic. It can also generate driving directions.
Find a route and directions
Learn how to get a route and directions using the solve method.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { solveRoute } from "@esri/arcgis-rest-routing";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
solveRoute({
stops: [
[-117.195677, 34.056383],
[-117.918976, 33.812092]
],
authentication
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});Service areas
Service areas show the distance you can travel on a road network from a location within a time or distance. The areas calculated consider factors such as travel time, distance, and traffic.
Find service areas
Learn how to get five, ten, and fifteen-minute drive time service areas of a location with the service method.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { serviceArea } from "@esri/arcgis-rest-routing";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
serviceArea({
facilities: [
[-123.1171, 49.2818] // Vancouver
],
authentication
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});