@aws/amazon-location-for-maplibre-gl-geocoder

中文文档
2.0.8发布于 2026/06/22TypeScriptESM + CJS构建来源已验证近 30 天下载 1.8万

Maplibre Plugin to Support Amazon Location Service Integration

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Usage with Module - Standalone GeoPlaces SDK
  4. Usage with a browser - Standalone GeoPlaces SDK
  5. Usage with Module - consolidated LocationClient SDK
  6. Usage with a browser - consolidated LocationClient SDK
  7. Documentation
  8. buildAmazonLocationMaplibreGeocoder
  9. getPlacesGeocoder
  10. Options Description
  11. Getting Help
  12. Contributing
  13. License

amazon-location-for-maplibre-gl-geocoder

Version Tests

This library is used to simplify the process of using Amazon Location Service with maplibre-gl-geocoder in JavaScript Applications.

Installation

Install this library from NPM for usage with modules:

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

You can also import HTML and CSS files for usage directly in the browser.

<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"
/>

Usage

Usage with Module - Standalone GeoPlaces SDK

This example uses the AWS SDK for JavaScript V3 to get a GeoPlacesClient to provide to the library, and AuthHelper for authenticating the GeoPlacesClient. It enables all APIs for the geocoder.

// 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());

Usage with a browser - Standalone GeoPlaces SDK

The clients and utility functions are available under the amazonLocationClient global.

Some of these example use the Amazon GeoPlacesClient. The Amazon GeoPlacesClient is based on the AWS SDK for JavaScript V3 and allows for making calls to Amazon Location through a script referenced in an HTML file.

This example uses the Amazon GeoPlacesClient to make a request that authenticates using an API Key.

<!-- 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>
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());

Usage with Module - consolidated LocationClient SDK

This example uses the AWS SDK for JavaScript V3 to get a LocationClient to provide to the library, and AuthHelper for authenticating the LocationClient. It enables all API's for the geocoder.

Usage with the consolidated LocationClient APIs require that you provide a PlacesIndex (Name of your places resource in your AWS Account) in the options variable.

// 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());

Usage with a browser - consolidated LocationClient SDK

The clients and utility functions are available under the amazonLocationClient global.

Some of these example use the Amazon Location Client. The Amazon Location Client is based on the AWS SDK for JavaScript V3 and allows for making calls to Amazon Location through a script referenced in an HTML file.

Usage with the LocationClient APIs require that you provide a PlacesIndex (Name of your places resource in your AWS Account) in the options variable.

This example uses the Amazon Location Client to make a request that that authenticates using Amazon Cognito.

<!-- 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>
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());

Documentation

Import the library and call the utility functions in the top-level namespace as needed. You can find more details about these functions in the Documentation section.

npm run typedoc

buildAmazonLocationMaplibreGeocoder

Creates an instance of the AmazonLocationMaplibreGeocoder which is the entry point to the other all other calls.

Using standalone GeoPlacesClient API Calls (client is instanceof GeoPlacesClient)

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

Using consolidated LocationClient API Calls (client is instance of LocationClient)

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

getPlacesGeocoder

Returns a ready to use IControl object that can be added directly to a map.

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 Description

OptionsDescription
enableAll?: booleanWhen false honours the explict set boolean flags for enableGetSuggestions and enableSearchByPlaceId. When true , sets both of these to true.
enableGetSuggestions?: booleanIf false, indicates that search will only occur on enter key press. If true, indicates that the Geocoder will search on the input box while it is being updated.
enableSearchByPlaceId?: booleanIf true, searches by placeID
omitSuggestionsWithoutPlaceId?: booleanOmits suggestion that don't have a PlaceId (e.g. query string suggestions, such as "pizza near me")
placeholder?: stringOverrides the string placeholder text in the input field
placesIndex?: stringThe name of the place index resource
flyTo?: boolean or FlyToOptionsIf false, animating the map to a selected result is disabled. If true, animating the map will use the default animation parameters. If an object, it will be passed as options to the map flyTo or fitBounds method providing control over the animation of the transition. Refer
zoom?: numberOn geocoded result what zoom level should the map animate to when a bbox isn't found in the response. If a bbox is found the map will fit to the bbox.
trackProximity?: booleanIf true, the geocoder proximity will automatically update based on the map view.
proximityMinZoom?: numberIf setting promiximity, this is the minimum zoom level at which to start taking it into account.
minLength?: numberMinimum number of characters to enter before results are shown.
reverseGeocode?: booleanIf true, enable reverse geocoding mode. In reverse geocoding, search input is expected to be coordinates in the form lat, lon, with suggestions being the reverse geocodes.
limit?: numberMaximum number of results to show.
collapsed?: booleanIf true, the geocoder control will collapse until hovered or in focus.
clearAndBlurOnEsc?: booleanIf true, the geocoder control will clear it's contents and blur when user presses the escape key.
clearOnBlur?: booleanIf true, the geocoder control will clear its value when the input blurs.
localGeocoderOnly?: booleanIf true, indicates that the localGeocoder results should be the only ones returned to the user. If false, indicates that the localGeocoder results should be combined with those from the Maplibre API with the localGeocoder results ranked higher.
debounceSearch?: numberSets the amount of time, in milliseconds, to wait before querying the server when a user types into the Geocoder input box. This parameter may be useful for reducing the total number of API calls made for a single query.
language?: stringSpecify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas. Defaults to the browser's language settings.
reverseMode?: "distance" or "score"If true, Markers will be added to the map at the location the top results for the query. If the value is an object, the marker will be constructed using these options. If false, no marker will be added to the map. Requires that options.maplibregl also be set.
getItemValue?: (item: CarmenGeojsonFeature) => stringA function that specifies how the selected result should be rendered in the search bar. HTML tags in the output string will not be rendered. Defaults to (item) => item.place_name
render?: (item: CarmenGeojsonFeature) => stringA function that specifies how the results should be rendered in the dropdown menu. Any HTML in the returned string will be rendered.
popupRender?: (item: CarmenGeojsonFeaturee) => stringA function that specifies how the results should be rendered in the popup menu. Any HTML in the returned string will be rendered.
filter?: (item: CarmenGeojsonFeature) => booleanA function which accepts a CarmenGeojsonFeature to filter out results from the Geocoding API response before they are included in the suggestions list. Return true to keep the item, false otherwise.

Refer MaplibreGeocoderOptions for additional usage information.

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

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

版本与发布记录

@aws/amazon-location-for-maplibre-gl-geocoder 共发布 15 个版本,首次发布于 2024/04/30;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.8latest2026/06/224 个月前
2.0.72026/06/094 个月前
2.0.62026/04/296 个月前
2.0.52025/10/211 年前
2.0.42025/09/061.2 年前
2.0.32025/05/201.5 年前

关于 @aws/amazon-location-for-maplibre-gl-geocoder 的常见问题

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

Maplibre Plugin to Support Amazon Location Service Integration

如何安装 @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 和提交记录判断。