@aws-cdk/aws-location-alpha

中文文档
2.275.0-alpha.0发布于 2026/10/27Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 7039

The CDK Construct Library for AWS::Location

原始使用文档
文档目录7 节
  1. Geofence Collection
  2. Tracker
  3. API key
  4. Legacy Resources
  5. Map
  6. Place Index
  7. Route Calculator

AWS::Location Construct Library


cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This module is part of the AWS Cloud Development Kit project.

Amazon Location Service lets you add location data and functionality to applications, which includes capabilities such as maps, points of interest, geocoding, routing, geofences, and tracking. Amazon Location provides location-based services (LBS) using high-quality data from global, trusted providers Esri and HERE. With affordable data, tracking and geofencing capabilities, and built-in metrics for health monitoring, you can build sophisticated location-enabled applications.

Geofence Collection

Geofence collection resources allow you to store and manage geofences—virtual boundaries on a map. You can evaluate locations against a geofence collection resource and get notifications when the location update crosses the boundary of any of the geofences in the geofence collection.

declare const key: kms.Key;

new location.GeofenceCollection(this, 'GeofenceCollection', {
  geofenceCollectionName: 'MyGeofenceCollection', // optional, defaults to a generated name
  kmsKey: key, // optional, defaults to use an AWS managed key
});

Use the grant() or grantRead() method to grant the given identity permissions to perform actions on the geofence collection:

declare const role: iam.Role;

const geofenceCollection = new location.GeofenceCollection(this, 'GeofenceCollection', {
  geofenceCollectionName: 'MyGeofenceCollection',
});

geofenceCollection.grantRead(role);

Tracker

A tracker stores position updates for a collection of devices. The tracker can be used to query the devices' current location or location history. It stores the updates, but reduces storage space and visual noise by filtering the locations before storing them.

For more information, see Trackers.

To create a tracker, define a Tracker:

declare const key: kms.Key;

new location.Tracker(this, 'Tracker', {
  trackerName: 'MyTracker', // optional, defaults to a generated name
  kmsKey: key, // optional, defaults to use an AWS managed key
});

Use the grant(), grantUpdateDevicePositions() or grantRead() method to grant the given identity permissions to perform actions on the geofence collection:

declare const role: iam.Role;

const tracker = new location.Tracker(this, 'Tracker', {
  trackerName: 'MyTracker',
});

tracker.grantRead(role);

If you want to associate a tracker with geofence collections, define a geofenceCollections property or use the addGeofenceCollections() method.

declare const geofenceCollection: location.GeofenceCollection;
declare const geofenceCollectionForAdd: location.GeofenceCollection;
declare const tracker: location.Tracker;

const tracker = new location.Tracker(this, 'Tracker', {
  trackerName: 'MyTracker',
  geofenceCollections: [geofenceCollection],
});

tracker.addGeofenceCollections(geofenceCollectionForAdd);

API key

API keys are a key value that is associated with specific Amazon Location Service resources or API in your AWS account, and specific actions that you can perform on those resources. You can use an API key in your application to make unauthenticated calls to the Amazon Location APIs for those resources.

For more information, see Use API keys to authenticate.

To create an API key, define an ApiKey:

new location.ApiKey(this, 'APIKeyAny', {
  // specify allowed actions
  allowMapsActions: [
    location.AllowMapsAction.GET_STATIC_MAP,
  ],
  allowPlacesActions: [
    location.AllowPlacesAction.GET_PLACE,
  ],
  allowRoutesActions: [
    location.AllowRoutesAction.CALCULATE_ISOLINES,
  ],
});

Note: ApiKey construct only supports Enhanced Places, Routes, and Maps This API key grants access to AWS-managed Places, Routes, and Maps.

Legacy Resources

AWS has released new Enhanced Places, Routes, and Maps. Since these use AWS-managed resources, users no longer need to create Maps, Places, and Routes resources themselves.

As a result, the following constructs are now considered legacy.

For more information, see developer guide.

Map

The Amazon Location Service Map resource gives you access to the underlying basemap data for a map. You use the Map resource with a map rendering library to add an interactive map to your application. You can add other functionality to your map, such as markers (or pins), routes, and polygon areas, as needed for your application.

For information about how to use map resources in practice, see Using Amazon Location Maps in your application.

To create a map, define a Map:

new location.Map(this, 'Map', {
  mapName: 'my-map',
  style: location.Style.VECTOR_ESRI_NAVIGATION,
  customLayers: [location.CustomLayer.POI],
});

Use the grant() or grantRendering() method to grant the given identity permissions to perform actions on the map:

declare const role: iam.Role;

const map = new location.Map(this, 'Map', {
  style: location.Style.VECTOR_ESRI_NAVIGATION,
});
map.grantRendering(role);

Place Index

A key function of Amazon Location Service is the ability to search the geolocation information. Amazon Location provides this functionality via the Place index resource. The place index includes which data provider to use for the search.

To create a place index, define a PlaceIndex:

new location.PlaceIndex(this, 'PlaceIndex', {
  placeIndexName: 'MyPlaceIndex', // optional, defaults to a generated name
  dataSource: location.DataSource.HERE, // optional, defaults to Esri
});

Use the grant() or grantSearch() method to grant the given identity permissions to perform actions on the place index:

declare const role: iam.Role;

const placeIndex = new location.PlaceIndex(this, 'PlaceIndex');
placeIndex.grantSearch(role);

Route Calculator

Route calculator resources allow you to find routes and estimate travel time based on up-to-date road network and live traffic information from your chosen data provider.

For more information, see Routes.

To create a route calculator, define a RouteCalculator:

new location.RouteCalculator(this, 'RouteCalculator', {
  routeCalculatorName: 'MyRouteCalculator', // optional, defaults to a generated name
  dataSource: location.DataSource.ESRI,
});

Use the grant() or grantRead() method to grant the given identity permissions to perform actions on the route calculator:

declare const role: iam.Role;

const routeCalculator = new location.RouteCalculator(this, 'RouteCalculator', {
  dataSource: location.DataSource.ESRI,
});
routeCalculator.grantRead(role);

版本与发布记录

@aws-cdk/aws-location-alpha 共发布 297 个版本,首次发布于 2022/12/08;过去 12 个月发布了 64 个版本。

版本发布日期距今
2.275.0-alpha.0latest2026/10/2712 天前
2.274.0-alpha.02026/10/2018 天前
2.273.0-alpha.02026/10/0930 天前
2.272.0-alpha.02026/09/301 个月前
2.271.0-alpha.02026/09/261 个月前
2.270.0-alpha.02026/09/181 个月前

关于 @aws-cdk/aws-location-alpha 的常见问题

@aws-cdk/aws-location-alpha 是什么?

The CDK Construct Library for AWS::Location

如何安装 @aws-cdk/aws-location-alpha?

在项目目录运行 npm install @aws-cdk/aws-location-alpha,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.5.0)、aws-cdk-lib(^2.275.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws-cdk/aws-location-alpha 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws-cdk/aws-location-alpha 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aws-cdk/aws-location-alpha 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aws-cdk/aws-location-alpha 可以商用吗?

@aws-cdk/aws-location-alpha 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-cdk/aws-location-alpha 的下载量有多少?

根据 npm 官方下载统计,@aws-cdk/aws-location-alpha 在 2026/10/08 – 2026/11/06 这 30 天内被下载 7,039 次,日均约 235 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws-cdk/aws-location-alpha 还在维护吗?

最新版本 2.275.0-alpha.0 发布于 2026/10/27(12 天前);至今共发布 297 个版本,其中过去 12 个月发布了 64 个;首次发布于 2022/12/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。