@geoapify/geocoder-autocomplete

中文文档
3.1.0发布于 2026/07/28MITTypeScriptESM + CJS零依赖近 30 天下载 4.8万

A JavaScript address autocomplete input, compatible with Leaflet, MapLibre, OpenLayers, and other map libraries for efficient location search and geocoding.

原始使用文档
文档目录13 节
  1. Table of Contents
  2. Features
  3. Quick Start
  4. 1. Get a Geoapify API Key
  5. 2. Choose an installation method
  6. 3. Listen for events
  7. 4. Clean up
  8. Documentation
  9. Try It Now
  10. Address Autocomplete Playground
  11. Live Demo Collection
  12. JSFiddle Demos
  13. Contributions and Support

Geoapify Geocoder Autocomplete

Docs

A lightweight TypeScript/JavaScript library that adds address autocomplete to web apps and can be used to build address autofill workflows. It is powered by the Geoapify Address Autocomplete API and supports filters, biases, category search, and custom request functions.

Geocoder Autocomplete

Table of Contents

Features

  • Customizable Address Input — Easily embed address autocomplete fields anywhere in your web app. Attach them to any HTML container (e.g., a DIV) and style them freely.
  • Powered by Geoapify APIs — Connects to the Geoapify Address Autocomplete API for real-time address suggestions. Custom request functions can connect a proxy or another compatible data source.
  • Advanced Search Customization — Fine-tune autocomplete behavior with flexible filters and bias settings (country, circle, rectangle, proximity) for highly relevant and localized results.
  • Structured Address Forms — Use the type parameter to build structured input fields (e.g., country, city, postcode, street, or amenity) for checkout or registration forms.
  • Category & POI Search — Enable category-based lookups such as restaurants, hotels, or gas stations. When active, category suggestions appear alongside address results for richer, context-aware searches.
  • Built-in Places List — Display categorized places directly in your interface with data from the Geoapify Places API. The list includes name, address, and opening hours, plus manual or scroll-based loading for more results.
  • Place Details Integration — Optionally fetch additional information and geometries from the Geoapify Place Details API — ideal for showing boundaries, polygons, or rich place context.
  • Customizable Look & Feel — Choose from four built-in light/dark themes or override the documented CSS classes.
  • Zero Dependencies — No external libraries required. Clean, lightweight, and framework-agnostic by design.

Quick Start

1. Get a Geoapify API Key

Visit Geoapify.com to sign up and get your free API key.

Geoapify offers a Free Plan that includes up to 3,000 address search requests per day, making it ideal for testing, prototyping, and small projects.

You can explore all available plans and usage limits on the Geoapify Pricing page.

2. Choose an installation method

Use either the package-manager setup or the CDN setup.

npm or Yarn

Install the package:

npm install @geoapify/geocoder-autocomplete
# or
yarn add @geoapify/geocoder-autocomplete

Add a container:

<div id="autocomplete"></div>

Then import the constructor and one of the packaged themes:

import { GeocoderAutocomplete } from '@geoapify/geocoder-autocomplete';
import '@geoapify/geocoder-autocomplete/styles/minimal.css';

const addressAutocomplete = new GeocoderAutocomplete(
  document.getElementById('autocomplete'),
  'YOUR_API_KEY',
  {
    placeholder: 'Enter address...',
    lang: 'en',
    limit: 5
  }
);

CDN

For a page without a build step, use this complete HTML setup:

<link rel="stylesheet" href="https://unpkg.com/@geoapify/geocoder-autocomplete@3/styles/minimal.css" />
<script src="https://unpkg.com/@geoapify/geocoder-autocomplete@3/dist/index.min.js"></script>

<div id="autocomplete"></div>

<script>
  const addressAutocomplete = new autocomplete.GeocoderAutocomplete(
    document.getElementById('autocomplete'),
    'YOUR_API_KEY',
    {
      placeholder: 'Enter address...',
      lang: 'en',
      limit: 5
    }
  );
</script>

This creates an interactive input that fetches address suggestions in real time. You can customize its behavior through the constructor and available options.

3. Listen for events

Subscribe to events to react to user selections or API updates:

addressAutocomplete.on('select', (feature) => {
  console.log('Selected location:', feature);
});

addressAutocomplete.on('suggestions', (suggestions) => {
  console.log('Address suggestions:', suggestions);
});

addressAutocomplete.on('open', () => console.log('Dropdown opened'));
addressAutocomplete.on('close', () => console.log('Dropdown closed'));

See the full list of available events in the Events Reference.

4. Clean up

Call destroy() before removing the host page or framework component:

addressAutocomplete.destroy();

This cancels active request lifecycles and removes the DOM listeners and markup owned by the control. Create a new instance if the view mounts again.

Documentation

Explore the guides for integrating, configuring, and maintaining the autocomplete:

Try It Now

Address Autocomplete Playground

Try the address autocomplete in the Playground. Experiment with different options, such as geocoding, biasing results, and more, to see how the autocomplete behavior adapts:

Live Demo Collection

A complete set of ready-to-run demos is available in this repository.
These examples demonstrate how to integrate Geoapify Geocoder Autocomplete into different use cases — from simple address forms to advanced map-based applications.

PreviewDescriptionDemoSource
One FieldOne Field Address Form — Single-field autocomplete inputOpenSource
Multi-fieldMulti-field Address Form — Step-by-step structured address inputOpenSource
Form + MapAddress Form + Map — Combined address search with interactive mapOpenSource
TypesAutocomplete Types — Filter results by location typeOpenSource
Filters & BiasFilters & Bias — Demonstrates filter and bias customizationOpenSource
EventsEvents Showcase — Demonstrates available events and callbacksOpenSource
Places — No MapPlaces Search (No Map) — Category search with built-in listOpenSource
LeafletLeaflet Integration — Address search and markers on interactive mapOpenSource
Leaflet + Custom ListLeaflet + Custom Places List — Custom UI for places resultsOpenSource
Leaflet + Built-in ListLeaflet + Built-in Places List — Category search with default UIOpenSource
MapLibre GLMapLibre GL Integration — Vector maps and reverse geocoding on clickOpenSource

JSFiddle Demos

Explore live examples demonstrating how to use Geoapify Geocoder Autocomplete with various map libraries and input scenarios.

DemoDescriptionLink
Address Field + Leaflet MapIntegrates the autocomplete field with a Leaflet map for interactive address search.Open JSFiddle
Address Field + MapLibre GL MapShows how to connect the autocomplete with a MapLibre GL map.Open JSFiddle
Address Form 1Simple address form demonstrating address search and autofill.Open JSFiddle
Address Form 2Another address form example with multiple fields.Open JSFiddle
Location Review for ShippingShows how to review and confirm a selected delivery location.Open JSFiddle
Custom Geocoding FunctionExample of a custom autocomplete logic using Geoapify’s Address Autocomplete API.Open JSFiddle

⚠️ Note: Address autocomplete speeds up user input, but no service guarantees 100% precision or global coverage.
For critical use cases such as shipping or delivery, show the selected point on a map and ask the user to confirm it. Reverse geocoding can help compare an address with chosen coordinates, but it does not independently prove delivery or entrance accuracy.

Contributions and Support

We welcome contributions! Here's how you can help:

  1. Open Issues: If you encounter any bugs or have feature requests, please open an issue on GitHub Issues.
  2. Submit a Pull Request: Fork the repository, make your changes, and submit a pull request for review.
  3. Documentation Updates: Help improve this documentation by submitting corrections or enhancements.

If you need assistance or have any questions, feel free to reach out to our support team at [email protected].

版本与发布记录

@geoapify/geocoder-autocomplete 共发布 36 个版本,首次发布于 2020/04/13;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.0latest2026/07/283 个月前
3.0.12025/11/111 年前
3.0.02025/11/071 年前
3.0.0-rc.1next2025/11/031 年前
2.2.12025/08/151.3 年前
2.2.02025/08/121.3 年前

关于 @geoapify/geocoder-autocomplete 的常见问题

@geoapify/geocoder-autocomplete 是什么?

A JavaScript address autocomplete input, compatible with Leaflet, MapLibre, OpenLayers, and other map libraries for efficient location search and geocoding.

如何安装 @geoapify/geocoder-autocomplete?

在项目目录运行 npm install @geoapify/geocoder-autocomplete,或使用 pnpm add / yarn add / bun add。

@geoapify/geocoder-autocomplete 支持 TypeScript 吗?

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

@geoapify/geocoder-autocomplete 支持 ESM 还是 CommonJS?

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

@geoapify/geocoder-autocomplete 可以商用吗?

@geoapify/geocoder-autocomplete 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@geoapify/geocoder-autocomplete 的下载量有多少?

根据 npm 官方下载统计,@geoapify/geocoder-autocomplete 在 2026/10/16 – 2026/11/14 这 30 天内被下载 48,449 次,日均约 1,615 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@geoapify/geocoder-autocomplete 还在维护吗?

最新版本 3.1.0 发布于 2026/07/28(3 个月前);至今共发布 36 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/04/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。