-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathcalculate-distance-async.js
More file actions
47 lines (41 loc) · 1.37 KB
/
calculate-distance-async.js
File metadata and controls
47 lines (41 loc) · 1.37 KB
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[location.JavaScript.distance.createDistAsyncV3]
import { fileURLToPath } from "node:url";
import {
CalculateRouteCommand,
ResourceNotFoundException,
LocationClient,
} from "@aws-sdk/client-location";
import data from "./inputs.json" with { type: "json" };
const region = "eu-west-1";
const locationClient = new LocationClient({ region: region });
export const main = async () => {
const routeCalcParams = {
CalculatorName: `${data.inputs.calculatorName}`,
DeparturePosition: [-122.3321, 47.6062],
DestinationPosition: [-123.1216, 49.2827],
TravelMode: "Car",
DistanceUnit: "Kilometers",
};
try {
const command = new CalculateRouteCommand(routeCalcParams);
const response = await locationClient.send(command);
console.log(
"Successfully calculated route. The distance in kilometers is : ",
response.Summary.Distance,
);
} catch (caught) {
if (caught instanceof ResourceNotFoundException) {
console.error(
`An conflict occurred: ${caught.message} \n Exiting program.`,
);
return;
}
}
};
// snippet-end:[location.JavaScript.distance.createDistAsyncV3]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
main();
}