|
| 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 | +<!--custom.overview.start--> |
| 8 | +<!--custom.overview.end--> |
| 9 | + |
| 10 | +_Amazon Location lets you easily and securely add maps, places, routes, geofences, and trackers, to your applications._ |
| 11 | + |
| 12 | +## ⚠ Important |
| 13 | + |
| 14 | +* 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/). |
| 15 | +* Running the tests might result in charges to your AWS account. |
| 16 | +* 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). |
| 17 | +* 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). |
| 18 | + |
| 19 | +<!--custom.important.start--> |
| 20 | +<!--custom.important.end--> |
| 21 | + |
| 22 | +## Code examples |
| 23 | + |
| 24 | +### Prerequisites |
| 25 | + |
| 26 | +For prerequisites, see the [README](../../README.md#Prerequisites) in the `javascriptv3` folder. |
| 27 | + |
| 28 | + |
| 29 | +<!--custom.prerequisites.start--> |
| 30 | +<!--custom.prerequisites.end--> |
| 31 | + |
| 32 | +### Get started |
| 33 | + |
| 34 | +- [Hello Amazon Location](hello.js#L4) (`ListGeofencesPaginator`) |
| 35 | + |
| 36 | + |
| 37 | +### Basics |
| 38 | + |
| 39 | +Code examples that show you how to perform the essential operations within a service. |
| 40 | + |
| 41 | +- [Learn the basics](scenarios/location-service-basics.js) |
| 42 | + |
| 43 | + |
| 44 | +### Single actions |
| 45 | + |
| 46 | +Code excerpts that show you how to call individual service functions. |
| 47 | + |
| 48 | +- [BatchUpdateDevicePosition](actions/batch-update-device-position.js#L4) |
| 49 | +- [CalculateRoute](actions/calculate-distance-async.js#L4) |
| 50 | +- [CreateGeofenceCollection](actions/create-geofence-collection.js#L4) |
| 51 | +- [CreateMap](actions/create-map.js#L4) |
| 52 | +- [CreateRouteCalculator](actions/create-route-calculator.js#L4) |
| 53 | +- [CreateTracker](actions/create-tracker.js#L4) |
| 54 | +- [DeleteGeofenceCollection](actions/delete-geofence-collection.js#L4) |
| 55 | +- [DeleteMap](actions/delete-map.js#L4) |
| 56 | +- [DeleteRouteCalculator](actions/delete-route-calculator.js#L4) |
| 57 | +- [DeleteTracker](actions/delete-tracker.js#L4) |
| 58 | +- [GetDevicePosition](actions/get-device-position.js#L4) |
| 59 | +- [PutGeofence](actions/put-geofence.js#L4) |
| 60 | + |
| 61 | + |
| 62 | +<!--custom.examples.start--> |
| 63 | +<!--custom.examples.end--> |
| 64 | + |
| 65 | +## Run the examples |
| 66 | + |
| 67 | +### Instructions |
| 68 | + |
| 69 | +**Note**: All code examples are written in ECMAscript 6 (ES6). For guidelines on converting to CommonJS, see |
| 70 | +[JavaScript ES6/CommonJS syntax](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sdk-examples-javascript-syntax.html). |
| 71 | + |
| 72 | +**Run a single action** |
| 73 | + |
| 74 | +```bash |
| 75 | +node ./actions/<fileName> |
| 76 | +``` |
| 77 | + |
| 78 | +**Run a scenario** |
| 79 | + |
| 80 | +Most scenarios can be run with the following command: |
| 81 | +```bash |
| 82 | +node ./scenarios/<fileName> |
| 83 | +``` |
| 84 | + |
| 85 | +**Run with options** |
| 86 | + |
| 87 | +Some actions and scenarios can be run with options from the command line: |
| 88 | +```bash |
| 89 | +node ./scenarios/<fileName> --option1 --option2 |
| 90 | +``` |
| 91 | +[util.parseArgs](https://nodejs.org/api/util.html#utilparseargsconfig) is used to configure |
| 92 | +these options. For the specific options available to each script, see the `parseArgs` usage |
| 93 | +for that file. |
| 94 | + |
| 95 | +<!--custom.instructions.start--> |
| 96 | +<!--custom.instructions.end--> |
| 97 | + |
| 98 | +#### Hello Amazon Location |
| 99 | + |
| 100 | +This example shows you how to get started using Amazon Location. |
| 101 | + |
| 102 | +```bash |
| 103 | +node ./hello.js |
| 104 | +``` |
| 105 | + |
| 106 | +#### Learn the basics |
| 107 | + |
| 108 | +This example shows you how to do the following: |
| 109 | + |
| 110 | +- Create an Amazon Location map. |
| 111 | +- Create an Amazon Location API key. |
| 112 | +- Display Map URL. |
| 113 | +- Create a geofence collection. |
| 114 | +- Store a geofence geometry. |
| 115 | +- Create a tracker resource. |
| 116 | +- Update the position of a device. |
| 117 | +- Retrieve the most recent position update for a specified device. |
| 118 | +- Create a route calculator. |
| 119 | +- Determine the distance between Seattle and Vancouver. |
| 120 | +- Use Amazon Location higher level APIs. |
| 121 | +- Delete the Amazon Location Assets. |
| 122 | + |
| 123 | +<!--custom.basic_prereqs.location_Scenario.start--> |
| 124 | +<!--custom.basic_prereqs.location_Scenario.end--> |
| 125 | + |
| 126 | + |
| 127 | +<!--custom.basics.location_Scenario.start--> |
| 128 | +<!--custom.basics.location_Scenario.end--> |
| 129 | + |
| 130 | + |
| 131 | +### Tests |
| 132 | + |
| 133 | +⚠ Running tests might result in charges to your AWS account. |
| 134 | + |
| 135 | + |
| 136 | +To find instructions for running these tests, see the [README](../../README.md#Tests) |
| 137 | +in the `javascriptv3` folder. |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +<!--custom.tests.start--> |
| 142 | +<!--custom.tests.end--> |
| 143 | + |
| 144 | +## Additional resources |
| 145 | + |
| 146 | +- [Amazon Location Developer Guide](https://docs.aws.amazon.com/location/latest/developerguide/what-is.html) |
| 147 | +- [Amazon Location API Reference](https://docs.aws.amazon.com/location/latest/APIReference/Welcome.html) |
| 148 | +- [SDK for JavaScript (v3) Amazon Location reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/location/) |
| 149 | + |
| 150 | +<!--custom.resources.start--> |
| 151 | +<!--custom.resources.end--> |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 156 | + |
| 157 | +SPDX-License-Identifier: Apache-2.0 |
0 commit comments