Skip to content

Commit ee09cb4

Browse files
committed
add initial files
1 parent a4213ac commit ee09cb4

20 files changed

+1393
-0
lines changed

.doc_gen/metadata/location_metadata.yaml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ location_CreateMap:
3636
- description:
3737
snippet_tags:
3838
- location.kotlin.create.map.main
39+
JavaScript:
40+
versions:
41+
- sdk_version: 3
42+
github: javascriptv3/example_code/location-services/actions
43+
sdkguide:
44+
excerpts:
45+
- description:
46+
snippet_tags:
47+
- location.JavaScript.map.createMapV3
3948
Java:
4049
versions:
4150
- sdk_version: 2
@@ -80,6 +89,15 @@ location_CreateGeofenceCollection:
8089
- description:
8190
snippet_tags:
8291
- location.kotlin.create.collection.main
92+
JavaScript:
93+
versions:
94+
- sdk_version: 3
95+
github: javascriptv3/example_code/location-services/actions
96+
sdkguide:
97+
excerpts:
98+
- description:
99+
snippet_tags:
100+
- location.JavaScript.geofence.createCollectionV3
83101
Java:
84102
versions:
85103
- sdk_version: 2
@@ -102,6 +120,15 @@ location_PutGeofence:
102120
- description:
103121
snippet_tags:
104122
- location.kotlin.put.geo.main
123+
JavaScript:
124+
versions:
125+
- sdk_version: 3
126+
github: javascriptv3/example_code/location-services/actions
127+
sdkguide:
128+
excerpts:
129+
- description:
130+
snippet_tags:
131+
- location.JavaScript.geofence.putV3
105132
Java:
106133
versions:
107134
- sdk_version: 2
@@ -124,6 +151,15 @@ location_CreateTracker:
124151
- description:
125152
snippet_tags:
126153
- location.kotlin.create.tracker.main
154+
JavaScript:
155+
versions:
156+
- sdk_version: 3
157+
github: javascriptv3/example_code/location-services/actions
158+
sdkguide:
159+
excerpts:
160+
- description:
161+
snippet_tags:
162+
- location.JavaScript.tracker.createTrackerV3
127163
Java:
128164
versions:
129165
- sdk_version: 2
@@ -146,6 +182,15 @@ location_BatchUpdateDevicePosition:
146182
- description:
147183
snippet_tags:
148184
- location.kotlin.update.device.position.main
185+
JavaScript:
186+
versions:
187+
- sdk_version: 3
188+
github: javascriptv3/example_code/location-services/actions
189+
sdkguide:
190+
excerpts:
191+
- description:
192+
snippet_tags:
193+
- location.JavaScript.device.batchUpdatePositionV3
149194
Java:
150195
versions:
151196
- sdk_version: 2
@@ -168,6 +213,15 @@ location_GetDevicePosition:
168213
- description:
169214
snippet_tags:
170215
- location.kotlin.get.device.position.main
216+
JavaScript:
217+
versions:
218+
- sdk_version: 3
219+
github: javascriptv3/example_code/location-services/actions
220+
sdkguide:
221+
excerpts:
222+
- description:
223+
snippet_tags:
224+
- location.JavaScript.position.getDevicePositionV3
171225
Java:
172226
versions:
173227
- sdk_version: 2
@@ -190,6 +244,15 @@ location_CreateRouteCalculator:
190244
- description:
191245
snippet_tags:
192246
- location.kotlin.create.calculator.main
247+
JavaScript:
248+
versions:
249+
- sdk_version: 3
250+
github: javascriptv3/example_code/location-services/actions
251+
sdkguide:
252+
excerpts:
253+
- description:
254+
snippet_tags:
255+
- location.JavaScript.routes.createRouteCalcV3
193256
Java:
194257
versions:
195258
- sdk_version: 2
@@ -212,6 +275,15 @@ location_CalculateRoute:
212275
- description:
213276
snippet_tags:
214277
- location.kotlin.calc.distance.main
278+
JavaScript:
279+
versions:
280+
- sdk_version: 3
281+
github: javascriptv3/example_code/location-services/actions
282+
sdkguide:
283+
excerpts:
284+
- description:
285+
snippet_tags:
286+
- location.JavaScript.distance.createDistAsyncV3
215287
Java:
216288
versions:
217289
- sdk_version: 2
@@ -234,6 +306,15 @@ location_DeleteGeofenceCollection:
234306
- description:
235307
snippet_tags:
236308
- location.kotlin.delete.collection.main
309+
JavaScript:
310+
versions:
311+
- sdk_version: 3
312+
github: javascriptv3/example_code/location-services/actions
313+
sdkguide:
314+
excerpts:
315+
- description:
316+
snippet_tags:
317+
- location.JavaScript.geofence.deleteCollectionV3
237318
Java:
238319
versions:
239320
- sdk_version: 2
@@ -278,6 +359,15 @@ location_DeleteMap:
278359
- description:
279360
snippet_tags:
280361
- location.kotlin.delete.map.main
362+
JavaScript:
363+
versions:
364+
- sdk_version: 3
365+
github: javascriptv3/example_code/location-services/actions
366+
sdkguide:
367+
excerpts:
368+
- description:
369+
snippet_tags:
370+
- location.JavaScript.geofence.deleteMapV3
281371
Java:
282372
versions:
283373
- sdk_version: 2
@@ -300,6 +390,15 @@ location_DeleteTracker:
300390
- description:
301391
snippet_tags:
302392
- location.kotlin.delete.tracker.main
393+
JavaScript:
394+
versions:
395+
- sdk_version: 3
396+
github: javascriptv3/example_code/location-services/actions
397+
sdkguide:
398+
excerpts:
399+
- description:
400+
snippet_tags:
401+
- location.JavaScript.tracker.deleteTrackerV3
303402
Java:
304403
versions:
305404
- sdk_version: 2
@@ -322,6 +421,15 @@ location_DeleteRouteCalculator:
322421
- description:
323422
snippet_tags:
324423
- location.kotlin.delete.calculator.main
424+
JavaScript:
425+
versions:
426+
- sdk_version: 3
427+
github: javascriptv3/example_code/location-services/actions
428+
sdkguide:
429+
excerpts:
430+
- description:
431+
snippet_tags:
432+
- location.JavaScript.calculator.deleteRouteCalculatorV3
325433
Java:
326434
versions:
327435
- sdk_version: 2
@@ -370,5 +478,14 @@ location_Scenario:
370478
- description: A wrapper class for &ALlong; SDK methods.
371479
snippet_tags:
372480
- location.java2.actions.main
481+
JavaScript:
482+
versions:
483+
- sdk_version: 3
484+
github: javascriptv3/example_code/location-services/scenarios
485+
sdkguide:
486+
excerpts:
487+
- description:
488+
snippet_tags:
489+
- LocationServices.javascriptv3.Scenario.basics
373490
services:
374491
location: {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Amazon Location code examples for the SDK for JavaScript (v3)
2+
3+
## Overview
4+
5+
Shows how to use the AWS SDK for JavaScript (v3) to work with Amazon Location Service.
6+
7+
## ⚠ Important
8+
9+
- Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
10+
- Running the tests might result in charges to your AWS account.
11+
- We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
12+
- This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
13+
14+
### Prerequisites
15+
16+
For prerequisites, see the [README](../../../../README.md#prerequisites) in the `javascriptv3` folder.
17+
18+
### Single Examples
19+
Code excerpts that show you how to call individual service functions.
20+
21+
### Learn the Basics
22+
23+
This example shows you how to do the following:
24+
- Create an Amazon Location map.
25+
- Create an Amazon Location API key.
26+
- Display Map URL.
27+
- Create a geofence collection.
28+
- Store a geofence geometry.
29+
- Create a tracker resource.
30+
- Update the position of a device.
31+
- Retrieve the most recent position update for a specified device.
32+
- Create a route calculator.
33+
- Determine the distance between Seattle and Vancouver.
34+
- Use Amazon Location higher level APIs.
35+
- Delete the Amazon Location Assets.
36+
37+
#### Run the scenario
38+
39+
```bash
40+
node converse-tool-scenario.js
41+
```
42+
## Tests
43+
44+
⚠ Running tests might result in charges to your AWS account.
45+
46+
To find instructions for running these tests, see the [README](../../../../README.md#tests) in the `javascriptv3` folder.
47+
48+
## Additional resources
49+
50+
- [Amazon Location Developer Guide](https://docs.aws.amazon.com/location/latest/developerguide/what-is.html)
51+
- [Amazon Location API Reference](https://docs.aws.amazon.com/location/latest/APIReference/Welcome.html)
52+
- [SDK for JavaScript (v3) Amazon Location reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/location/)
53+
54+
---
55+
56+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
57+
58+
SPDX-License-Identifier: Apache-2.0
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// snippet-start:[location.JavaScript.device.batchUpdatePositionV3]
5+
import { fileURLToPath } from "node:url";
6+
import {
7+
BatchUpdateDevicePositionCommand,
8+
LocationClient,
9+
ResourceNotFoundException,
10+
} from "@aws-sdk/client-location";
11+
import data from "./inputs.json" with { type: "json" };
12+
const region = "eu-west-1";
13+
const locationClient = new LocationClient({ region: region });
14+
const updateDevicePosParams = {
15+
TrackerName: `${data.inputs.trackerName}`,
16+
Updates: [
17+
{
18+
DeviceId: `${data.inputs.deviceId}`,
19+
SampleTime: new Date(),
20+
Position: [-122.4194, 37.7749],
21+
},
22+
],
23+
};
24+
async function main() {
25+
try {
26+
const command = new BatchUpdateDevicePositionCommand(updateDevicePosParams);
27+
const response = await locationClient.send(command);
28+
//console.log("response ", response.Errors[0].Error);
29+
30+
console.log(
31+
`Device with id ${data.inputs.deviceId} was successfully updated in the location tracking system. `,
32+
response,
33+
);
34+
} catch (error) {
35+
console.log("error ", error);
36+
}
37+
}
38+
39+
// snippet-end:[location.JavaScript.device.batchUpdatePositionV3]
40+
41+
// Invoke main function if this file was run directly.
42+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
43+
main();
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// snippet-start:[location.JavaScript.distance.createDistAsyncV3]
5+
import { fileURLToPath } from "node:url";
6+
import {
7+
CalculateRouteCommand,
8+
ResourceNotFoundException,
9+
LocationClient,
10+
} from "@aws-sdk/client-location";
11+
import data from "./inputs.json" with { type: "json" };
12+
13+
const region = "eu-west-1";
14+
const locationClient = new LocationClient({ region: region });
15+
16+
async function main() {
17+
const routeCalcParams = {
18+
CalculatorName: `${data.inputs.calculatorName}`,
19+
DeparturePosition: [-122.3321, 47.6062],
20+
DestinationPosition: [-123.1216, 49.2827],
21+
TravelMode: "Car",
22+
DistanceUnit: "Kilometers",
23+
};
24+
try {
25+
const command = new CalculateRouteCommand(routeCalcParams);
26+
const response = await locationClient.send(command);
27+
28+
console.log(
29+
"Successfully calculated route. The distance in kilometers is : ",
30+
response.Summary.Distance,
31+
);
32+
} catch (caught) {
33+
if (caught instanceof ResourceNotFoundException) {
34+
console.error(
35+
`An conflict occurred: ${caught.message} \n Exiting program.`,
36+
);
37+
return;
38+
}
39+
}
40+
}
41+
42+
// snippet-end:[location.JavaScript.distance.createDistAsyncV3]
43+
44+
// Invoke main function if this file was run directly.
45+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
46+
main();
47+
}

0 commit comments

Comments
 (0)