Skip to content

aws-geospatial/amazon-location-client-js

Amazon Location JavaScript Client

This is a distribution of the AWS SDK for JavaScript v3 containing the standalone Maps, Places, and Routes SDKs, the Location SDK, our authentication helper, and credential providers intended for use in browsers.

Installation

Usage with a browser

Add the script to an HTML file for usage directly in the browser.

<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>

Usage with modules

We recommend using @aws-sdk/client-geo-maps, @aws-sdk/client-geo-places, @aws-sdk/client-geo-routes, @aws-sdk/client-location and @aws-sdk/credential-providers from the AWS SDK for JavaScript v3 if possible to get the full benefit of the modularized AWS SDK.

Usage

All functions are available under the amazonLocationClient global.

API Key

This example uses the Amazon Location Client to make a request that authenticates using an API key.

<!-- Import the Amazon Location Client -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>
// Create an authentication helper instance using an API key and region
const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");

const client = new amazonLocationClient.GeoRoutesClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.routes.CalculateRoutesCommand(input);
const response = await client.send(command);

Cognito

This example uses the Amazon Location Client to make a request that authenticates using Amazon Cognito. For more information on setting up Amazon Cognito identity pools, please refer to this guide.

// Create an authentication helper instance using credentials from Amazon Cognito
const authHelper = await amazonLocationClient.withIdentityPoolId("<Identity Pool ID>");

const client = new amazonLocationClient.GeoRoutesClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.routes.CalculateRoutesCommand(input);
const response = await client.send(command);

Documentation

The APIs for the different client SDKs are grouped separately.

The standalone Maps SDK commands are grouped into a maps namespace. For example:

// Create an authentication helper instance using an API key and region
const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");

const client = new amazonLocationClient.GeoMapsClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.maps.GetStaticMapCommand(input);
const response = await client.send(command);

The standalone Places SDK commands are grouped into a places namespace. For example:

// Create an authentication helper instance using an API key and region
const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");

const client = new amazonLocationClient.GeoPlacesClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.places.GetPlaceCommand(input);
const response = await client.send(command);

The standalone Routes SDK commands are grouped into a routes namespace. For example:

// Create an authentication helper instance using an API key and region
const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");

const client = new amazonLocationClient.GeoRoutesClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.routes.CalculateRoutesCommand(input);
const response = await client.send(command);

The Location SDK commands are under the top-level namespace. For example:

// Create an authentication helper instance using an API key and region
const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");

const client = new amazonLocationClient.LocationClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.ListGeofencesCommand(input);
const response = await client.send(command);

Refer to @aws-sdk/client-geo-maps, @aws-sdk/client-geo-places, @aws-sdk/client-geo-routes, @aws-sdk/client-location and @aws-sdk/credential-providers for further documentation.

Getting Help

The best way to interact with our team is through GitHub. You can open an issue and choose from one of our templates for bug reports, feature requests or guidance. If you have a support plan with AWS Support, you can also create a new support case.

Please make sure to check out the following resources before opening an issue:

Contributing

We welcome community contributions and pull requests. See CONTRIBUTING.md for information on how to set up a development environment and submit code.

License

Amazon Location JavaScript Client is distributed under the Apache License, Version 2.0, see LICENSE.txt and NOTICE.txt for more information.