# @aws/amazon-location-for-maplibre-gl-geocoder 中文文档

规范地址：https://npmcn.com/package/%40aws/amazon-location-for-maplibre-gl-geocoder/

版本：2\.0\.8
npm 元数据更新时间：2026-06-22T20:38:44.509Z
中文译文更新时间：2026-11-07T14:35:17.198Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aws/amazon-location-for-maplibre-gl-geocoder
原文对照：https://npmcn.com/package/%40aws/amazon-location-for-maplibre-gl-geocoder/?lang=original
项目主页：https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder#readme
源码仓库：https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.4 MB，23 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2024-04-29T20:11:39.697Z
- 最新版本发布：2026-06-22T15:33:50.129Z
- 近 30 天下载量：17705（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：15（近 12 个月 3 个）

## 中文简介

支持 Amazon 位置服务整合的 Maplibre 插件

## 安装

```sh
npm install @aws/amazon-location-for-maplibre-gl-geocoder
```

也可以使用：`pnpm add @aws/amazon-location-for-maplibre-gl-geocoder`、`yarn add @aws/amazon-location-for-maplibre-gl-geocoder`、`bun add @aws/amazon-location-for-maplibre-gl-geocoder`

## README

# 地图地图

[![Version](https://img.shields.io/npm/v/@aws/amazon-location-for-maplibre-gl-geocoder?style=flat)](https://www.npmjs.com/package/@aws/amazon-location-for-maplibre-gl-geocoder) [![Tests](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/actions/workflows/build.yml/badge.svg)](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/actions/workflows/build.yml)

此库用于简化使用过程 [亚马逊定位服务](https://aws.amazon.com/location/) 与 [映射- gl- 地理编码器](https://github.com/maplibre/maplibre-gl-geocoder) 在JavaScript应用程序中.

## 安装

从国家防范机制安装此库供模块使用:

```console
npm install @aws/amazon-location-for-maplibre-gl-geocoder
```

您也可以导入 HTML 和 CSS 文件供浏览器直接使用.

```html
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2"></script>
<link
  href="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2/dist/amazon-location-for-mlg-styles.css"
  rel="stylesheet"
/>
```

## 使用量

### 模块的用法 - 独立的地盘 SDK

此示例使用 [JavaScript V3 的 AWS SDK 软件](https://github.com/aws/aws-sdk-js-v3) 获得一个 GeoPlacesClient 供图书馆使用,以及 [认证帮助](https://github.com/aws-geospatial/amazon-location-utilities-auth-helper-js) 用于认证 GeoPlacesClient。 它为地理编码器提供了所有API.

```javascript
// Import MapLibre GL JS
import maplibregl from "maplibre-gl";
// Import from the AWS JavaScript SDK V3
import { GeoPlacesClient } from "@aws-sdk/client-geo-places";
// Import the utility functions
import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper";
// Import the AmazonLocationMaplibreGeocoder
import {
  buildAmazonLocationMaplibreGeocoder,
  AmazonLocationMaplibreGeocoder,
} from "@aws/amazon-location-for-maplibre-gl-geocoder";

const apiKey = "<API Key>";
const mapName = "Standard";
const region = "<Region>"; // region containing Amazon Location API Key

// Create an authentication helper instance using an API key and region
const authHelper = await withAPIKey(apiKey, region);

const client = new GeoPlacesClient(authHelper.getClientConfig());

// Render the map
const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/v2/styles/${mapStyle}/descriptor?key=${apiKey}`,
});

// Gets an instance of the AmazonLocationMaplibreGeocoder Object.
const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, { enableAll: true });

// Now we can add the Geocoder to the map.
map.addControl(amazonLocationMaplibreGeocoder.getPlacesGeocoder());
```

### 使用浏览器 - 独立的 GeoPlaces SDK

客户和公用事业职能可在 `amazonLocationClient` 全球.

> 其中一些例子使用"亚马逊地平板电脑". 亚马逊GeoPlacesClient基于 [JavaScript V3 的 AWS SDK 软件](https://github.com/aws/aws-sdk-js-v3) ,并允许通过 HTML 文件引用的脚本给 Amazon Location 打电话.

这个例子使用"亚马逊GeoPlacesClient"来提出使用API密钥认证的请求.

```html
<!-- Import the Amazon Location For Maplibre Geocoder -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2"></script>
<link
  href="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2/dist/amazon-location-for-mlg-styles.css"
  rel="stylesheet"
/>
<!-- Import the Amazon GeoPlacesClient -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>
```

```javascript
const apiKey = "<API Key>";
const mapStyle = "Standard";
const region = "<Region>"; // region containing Amazon Location API key

// Create an authentication helper instance using an API key and region
const authHelper = await amazonLocationClient.withAPIKey(apiKey, region);

const client = new amazonLocationClient.GeoPlacesClient(authHelper.getClientConfig());

// Render the map
const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/v2/styles/${mapStyle}/descriptor?key=${apiKey}`,
});

// Initialize the AmazonLocationMaplibreGeocoder object
const amazonLocationMaplibreGeocoderObject = amazonLocationMaplibreGeocoder.buildAmazonLocationMaplibreGeocoder(
  client,
  { enableAll: true },
);

// Use the AmazonLocationWithMaplibreGeocoder object to add a geocoder to the map.
map.addControl(amazonLocationMaplibreGeocoderObject.getPlacesGeocoder());
```

### 模块的使用 -- -- 合并位置

此示例使用 [JavaScript V3 的 AWS SDK 软件](https://github.com/aws/aws-sdk-js-v3) 获取一个地址地址地址向图书馆提供,以及 [认证帮助](https://github.com/aws-geospatial/amazon-location-utilities-auth-helper-js) 用于认证位置中心。 它可以让所有API用于地理编码器.

使用合并的 LaceClient API 需要您在选项变量中提供 PlacesIndex(您在 AWS 账户中的位置资源名称) .

```javascript
// Import MapLibre GL JS
import maplibregl from "maplibre-gl";
// Import from the AWS JavaScript SDK V3
import { LocationClient } from "@aws-sdk/client-location";
// Import the utility functions
import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper";
// Import the AmazonLocationMaplibreGeocoder
import {
  buildAmazonLocationMaplibreGeocoder,
  AmazonLocationMaplibreGeocoder,
} from "@aws/amazon-location-for-maplibre-gl-geocoder";

const identityPoolId = "<Identity Pool ID>";
const mapName = "<Map Name>";
const region = "<Region>"; // region containing Amazon Location resource
const placeIndex = "<PlaceIndexName>"; // Name of your places resource in your AWS Account.

// Create an authentication helper instance using credentials from Cognito
const authHelper = await withIdentityPoolId(identityPoolId, region);

const client = new LocationClient(authHelper.getLocationClientConfig());

// Render the map
const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/maps/v0/maps/${mapName}/style-descriptor`,
  ...authHelper.getMapAuthenticationOptions(),
});

// Gets an instance of the AmazonLocationMaplibreGeocoder Object.
const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, {
  enableAll: true,
  placesIndex: placeIndex,
});

// Now we can add the Geocoder to the map.
map.addControl(amazonLocationMaplibreGeocoder.getPlacesGeocoder());
```

### 使用浏览器 - 合并位置Client SDK

客户和公用事业职能可在 `amazonLocationClient` 全球.

> 其中一些例子使用亚马逊地块客户端. Amazon 位置客户端基于 [JavaScript V3 的 AWS SDK 软件](https://github.com/aws/aws-sdk-js-v3) ,并允许通过 HTML 文件引用的脚本给 Amazon Location 打电话.

使用 LaceClient API 需要您在选项变量中提供 PlacesIndex(您在 AWS 账户中的位置资源名称) .

这个例子使用亚马逊地标客户端来请求使用亚马逊地标认证.

```html
<!-- Import the Amazon Location For Maplibre Geocoder -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2"></script>
<link
  href="https://cdn.jsdelivr.net/npm/@aws/amazon-location-for-maplibre-gl-geocoder@2/dist/amazon-location-for-mlg-styles.css"
  rel="stylesheet"
/>
<!-- Import the Amazon Location Client -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>
```

```javascript
const identityPoolId = "<Identity Pool ID>";
const mapName = "<Map Name>";
const region = "<Region>"; // region containing Amazon Location resource
const placeIndex = "<PlaceIndexName>"; // Name of your places resource in your AWS Account.

// Create an authentication helper instance using credentials from Cognito
const authHelper = await amazonLocationClient.withIdentityPoolId(identityPoolId);

// Initialize the LocationClient
const client = new LocationClient(authHelper.getLocationClientConfig());

// Render the map
const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/maps/v0/maps/${mapName}/style-descriptor`,
  ...authHelper.getMapAuthenticationOptions(),
});

// Initialize the AmazonLocationMaplibreGeocoder object
const amazonLocationMaplibreGeocoderObject = amazonLocationMaplibreGeocoder.buildAmazonLocationMaplibreGeocoder(
  client,
  { enableAll: true, placesIndex: placeIndex },
);

// Use the AmazonLocationWithMaplibreGeocoder object to add a geocoder to the map.
map.addControl(amazonLocationMaplibreGeocoderObject.getPlacesGeocoder());
```

## 文档

导入库并按需要调用顶级命名空间中的公用功能 。 您可以在文档部分找到这些功能的更多细节.

```console
npm run typedoc
```

### `buildAmazonLocationMaplibreGeocoder`

创建 AmazonLocationMaplibreGeocoder 实例,它是其他所有呼叫的切入点.

使用独立的GeoPlacesClient API呼叫(客户端为GeoPlacesClient)

```javascript
const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, { enableAll: true });
```

使用合并的 LaceClient API 呼叫( 客户端为 LaceClient 实例)

```javascript
const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, {
  enableAll: true,
  placesIndex: placeIndex,
});
```

### `getPlacesGeocoder`

返回一个可以直接添加到地图中的可用 IControl 对象.

```javascript
const geocoder = getPlacesGeocoder();

// Initialize map see: <insert link to initializing a map instance here>
let map = await initializeMap();

// Add the geocoder to the map.
map.addControl(geocoder);
```

### `Options` 说明

| 选项 | 说明 |
| --- | --- |
| 全部启用 ?: 布尔 | 当错误遵守时, explicict 设置布尔标记, 用于启用 GetSug建议并启用SearchByPlaceId 。 当它们都是真的时. |
| 启用“ 获取建议” 吗 : boolean | 如果错误, 则表示仅在输入密钥上进行搜索 。 如果为真,则表示Geocoder将在更新时在输入框上搜索. |
| 启用SearchByPlaceId?:布尔 | 如果为真, 则按位置ID搜索 |
| 省略不带标签的建议吗 : 布尔 | Omits 建议没有 PlaceId(例如查询字符串建议,例如"靠近我的皮扎") |
| 占位符 ?: 字符串 | 覆盖输入字段中的字符串占位符文本 |
| index 吗 : 字符串 | 位置索引资源的名称 |
| 飞去?:布尔或 [飞到选项](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FlyToOptions/) | 如果错误,将映射到选定结果的动画将被禁用。 如果选中的话, 动画地图将会使用默认的动画参数 。 如果一个对象,它将作为选项传递到 映射 flyTo 或 `fitBounds` 方法提供对过渡动画的控制. [参考](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FlyToOptions/) |
| 缩放 ? 数字 | 在地理编码上的结果是,当响应中找不到一个bbox时,地图的动能应该放大到什么水平. 如果找到 bbox , 地图将适合 bbox . |
| 轨迹近似 ?: 布尔 | 如果真实, 地理编码器的相近性会自动根据地图视图更新 . |
| 靠近MinZoom吗 | 如果设置平面, 这是最小的缩放级别, 开始考虑它 . |
| 明伦斯? : 号码 | 在显示结果前输入的最小字符数 . |
| 倒转吉奥码 ?: 布尔 | 如果为真,则启用倒转地理编码模式。 在倒向地理编码中,搜索输入预计将以正方形(tat,lon)为坐标,建议为倒向地理编码. |
| 限制? : 数字 | 要显示的最大结果数 . |
| 崩溃 ?: 布尔 | 如果是真的,地理编码器控制会崩溃,直到徘徊或被聚焦. |
| \- 布尔克 | 如果真实,地理编码器控制会清除内容并模糊用户按出逃密钥时. |
| 清除 Blur 吗 : 布尔 | 如果真实,当输入模糊时,地理编码器控制会清除其值. |
| (原始内容存档于2018-03-21) (英语). localGeocoder Only?: boolean | 如果为真,则表示本地Geocoder结果应该是返回用户的唯一结果. 如果错误,则表示本地的Geocoder结果应当与来自Maplibre API的结果与本地的Geocoder结果的排名相加. |
| 解开搜索器 | 设定一个用户输入 Geocoder 输入框时在询问服务器前等待的时间, 以毫秒计 。 此参数可能有助于减少为单一查询而发出的API呼叫的总数. |
| 语言 ? : 字符串 | 指定用于响应文本和查询结果加权的语言。 选项是IETF语言标记,由强制性的ISO 639-1语言代码以及国家或脚本可选的一个或多个IETF子标签组成. 多个值也可以指定,用逗号分隔. 默认浏览器的语言设置 . |
| 倒转模式 : “ 距离 ” 或 “ 分数 ” | 如果真是这样, [`Markers`](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/) 将在查询的顶端结果位置上添加到地图中。 如果值是对象,则会使用这些选项来构建标记. 如果错误, 地图上不会添加标记 。 需要设置选项. maplibregl . |
| 获得项目值? (项目: [卡门·盖奥杰森福特](https://maplibre.org/maplibre-gl-geocoder/types/CarmenGeojsonFeature.html)) qq 字符串 | 指定如何在搜索栏中提供选定结果的函数。 输出字符串中的 HTML 标记将不会被渲染 。 默认为( 项 ) {} 项. place name |
| (项目: [卡门·盖奥杰森福特](https://maplibre.org/maplibre-gl-geocoder/types/CarmenGeojsonFeature.html)) qq 字符串 | 指定如何在下放菜单中提供结果的函数 。 返回字符串中的任何 HTML 都会被渲染 . |
| 弹出者 [卡门·盖奥杰森福特](https://maplibre.org/maplibre-gl-geocoder/types/CarmenGeojsonFeature.html)(e) qq 字符串 | 指定弹出菜单中应如何提供结果的函数 。 返回字符串中的任何 HTML 都会被渲染 . |
| 过滤器 : (项目 : [卡门·盖奥杰森福特](https://maplibre.org/maplibre-gl-geocoder/types/CarmenGeojsonFeature.html)? 布尔? | 一个接受CarmenGeojsonFeature的函数在将Geocoding API响应纳入建议列表之前过滤出结果. 返回真实的保存物品, 否则是假的. |

参考 [Maplibre 地理编码器选项](https://maplibre.org/maplibre-gl-geocoder/types/MaplibreGeocoderOptions.html) 额外使用信息.

## 获取帮助

与我们团队互动的最佳方式是通过GitHub. 你们可以 [打开一个问题](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/issues/new/choose) 从我们的模板中选择一个 [错误报告](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/issues/new?assignees=&labels=bug%2C+needs-triage&template=---bug-report.md&title=), (中文(简体) ), [特性请求](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/issues/new?assignees=&labels=feature-request&template=---feature-request.md&title=) 或者说 [指导](https://github.com/aws-geospatial/amazon-location-for-maplibre-gl-geocoder/issues/new?assignees=&labels=guidance%2C+needs-triage&template=---questions---help.md&title=)。 。 。 . 如果您有支持计划 [AWS 支持](https://aws.amazon.com/premiumsupport/),也可以创建新的支持案件.

请在开始发行前检查以下资源:

-   我们 [更改日志](https://npmcn.com/package/%40aws/amazon-location-for-maplibre-gl-geocoder/CHANGELOG.md) 用于最近的变化.

## 捐款

见 [捐款](https://npmcn.com/package/%40aws/amazon-location-for-maplibre-gl-geocoder/CONTRIBUTING.md#security-issue-notifications) 更多信息.

## 许可证

这个项目根据Apache-2.0许可证获得许可证.

## 常见问题

### @aws/amazon-location-for-maplibre-gl-geocoder 是什么？

支持 Amazon 位置服务整合的 Maplibre 插件

### 如何安装 @aws/amazon-location-for-maplibre-gl-geocoder？

在项目目录运行 npm install @aws/amazon-location-for-maplibre-gl-geocoder，或使用 pnpm add / yarn add / bun add。

### @aws/amazon-location-for-maplibre-gl-geocoder 支持 TypeScript 吗？

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

### @aws/amazon-location-for-maplibre-gl-geocoder 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @aws/amazon-location-for-maplibre-gl-geocoder 可以商用吗？

@aws/amazon-location-for-maplibre-gl-geocoder 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @aws/amazon-location-for-maplibre-gl-geocoder 的下载量有多少？

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

### @aws/amazon-location-for-maplibre-gl-geocoder 还在维护吗？

最新版本 2\.0\.8 发布于 2026/06/22（4 个月前）；至今共发布 15 个版本，其中过去 12 个月发布了 3 个；首次发布于 2024/04/30。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

