快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-nativegeocoder`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/nativegeocoder/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nativegeocoder` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
npm install @capgo/capacitor-nativegeocodernpx cap sync导入
“导入”章节import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';快速入门
章节标题为“快速入门”import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';
const { addresses } = await NativeGeocoder.reverseGeocode({ latitude: 48.8566, longitude: 2.3522, maxResults: 1,});示例:正向地理编码地址
标题为“示例:正向地理编码地址”的章节const { addresses } = await NativeGeocoder.forwardGeocode({ address: '1 Infinite Loop, Cupertino, CA', maxResults: 3,});常见坑点
章节标题为“常见陷阱”- Web API 密钥:在 Web 端进行反向和正向地理编码时,需要在 options 中提供 Google Geocoding API 密钥。
- 区域设置:设置
useLocale或defaultLocale用于在国际化场景下显示地址。 - 地址不明确: 抛出
maxResults并让用户从匹配项中进行选择。
API 概览
章节标题:“API 概览”reverseGeocode
标题为 “reverseGeocode” 的章节将经纬度转换为地址
import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';
const result = await NativeGeocoder.reverseGeocode({ latitude: 48.8566, longitude: 2.3522,});console.log(result);forwardGeocode
标题为 “forwardGeocode” 的章节将地址转换为经纬度
import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';
const result = await NativeGeocoder.forwardGeocode({ addressString: 'address-string' });console.log(result);类型参考
“类型参考” 章节ReverseOptions
“ReverseOptions” 章节export interface ReverseOptions { /** * latitude is a number representing the latitude of the location. */ latitude: number; /** * longitude is a number representing the longitude of the location. */ longitude: number; /** * Localise the results to the given locale. */ useLocale?: boolean; /** * locale is a string in the format of language_country, for example en_US. */ defaultLocale?: string; /** * Max number of results to return. */ maxResults?: number; /** * Only used for web platform to use google api */ apiKey?: string; /** * Only used for web platform to use google api */ resultType?: string;}Address
“Address” 章节export interface Address { latitude: number; longitude: number; countryCode: string; countryName: string; postalCode: string; administrativeArea: string; subAdministrativeArea: string; locality: string; subLocality: string; thoroughfare: string; subThoroughfare: string; areasOfInterest: string[];}ForwardOptions
“ForwardOptions” 章节export interface ForwardOptions { /** * address is a string of the address to be geocoded. */ addressString: string; /** * Localise the results to the given locale. */ useLocale?: boolean; /** * locale is a string in the format of language_country, for example en_US. */ defaultLocale?: string; /** * Max number of results to return. */ maxResults?: number; /** * Only used for web platform to use google api */ apiKey?: string;}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-nativegeocoder 针对使用 @capgo/capacitor-nativegeocoder 中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。