Langsung ke konten

Panduan Memulai

GitHub

Anda bisa menggunakan AI-Assisted Setup kami untuk menginstal plugin ini. Tambahkan skill Capgo ke tool AI Anda dengan command berikut:

Jendela terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Lalu gunakan prompt berikut:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-nativegeocoder` plugin in my project.

Jika Anda lebih memilih Manual Setup, instal plugin dengan menjalankan perintah berikut dan ikuti petunjuk khusus platform di bawah ini:

Jendela terminal
npm install @capgo/capacitor-nativegeocoder
npx 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,
});
  • Kunci web API: reverse dan forward geocoding di web memerlukan kunci API Google Geocoding di bagian options.
  • Locale: atur useLocale atau defaultLocale saat menampilkan alamat secara internasional.
  • Alamat tidak jelas: munculkan maxResults and let users pick among matches.

Konversi latitude dan longitude ke alamat

import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';
const result = await NativeGeocoder.reverseGeocode({
latitude: 48.8566,
longitude: 2.3522,
});
console.log(result);

Konversi alamat ke latitude dan longitude

import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';
const result = await NativeGeocoder.forwardGeocode({ addressString: 'address-string' });
console.log(result);
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;
}
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[];
}
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;
}

Halaman ini dibuat dari plugin src/definitions.ts. Jalankan ulang sync saat API publik berubah di upstream.

Jika Anda menggunakan Panduan Memulai untuk merencanakan operasi dashboard dan API, hubungkan dengan Menggunakan @capgo/capacitor-nativegeocoder untuk kapabilitas native di Menggunakan @capgo/capacitor-nativegeocoder, Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, Kunci API untuk detail implementasi di API Keys, dan Perangkat untuk detail implementasi di Devices.