Capacitor plugin for native forward and reverse geocoding
npm install @capgo/nativegeocoder
npx cap sync
then import this into your code:
import { NativeGeocoder } from '@capgo/nativegeocoder';
Apple requires privacy descriptions to be specified in Info.plist
for location information:
NSLocationAlwaysUsageDescription
(Privacy - Location Always Usage Description
)NSLocationWhenInUseUsageDescription
(Privacy - Location When In Use Usage Description
)Read about Configuring Info.plist
in the iOS Guide for more information on setting iOS permissions in Xcode
This API requires the following permissions be added to your AndroidManifest.xml
:
<!-- Geolocation API -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
reverseGeocode(options: reverseOptions) => any
Convert latitude and longitude to an address
Param | Type |
---|---|
options |
reverseOptions |
Returns: any
Since: 0.0.1
forwardGeocode(options: ForwardOptions) => any
Convert an address to latitude and longitude
Param | Type |
---|---|
options |
ForwardOptions |
Returns: any
Since: 0.0.1
Prop | Type | Description |
---|---|---|
latitude |
number |
latitude is a number representing the latitude of the location. |
longitude |
number |
longitude is a number representing the longitude of the location. |
useLocale |
boolean |
Localise the results to the given locale. |
defaultLocale |
string |
locale is a string in the format of language_country, for example en_US. |
maxResults |
number |
Max number of results to return. |
apiKey |
string |
Only used for web platform to use google api |
Prop | Type |
---|---|
latitude |
number |
longitude |
number |
countryCode |
string |
countryName |
string |
postalCode |
string |
administrativeArea |
string |
subAdministrativeArea |
string |
locality |
string |
subLocality |
string |
thoroughfare |
string |
subThoroughfare |
string |
areasOfInterest |
{} |
Prop | Type | Description |
---|---|---|
addressString |
string |
address is a string of the address to be geocoded. |
useLocale |
boolean |
Localise the results to the given locale. |
defaultLocale |
string |
locale is a string in the format of language_country, for example en_US. |
maxResults |
number |
Max number of results to return. |
apiKey |
string |
Only used for web platform to use google api |
To @sebastianbaar and his work on cordova-plugin-nativegeocoder what he made was very inspiring
The @capgo/nativegeocoder
package is a Capacitor plugin that provides native forward and reverse geocoding functionality. Geocoding is the process of converting addresses into geographic coordinates (latitude and longitude) and vice versa.
To use the @capgo/nativegeocoder
package, follow the steps below:
Install the package using npm:
npm install @capgo/nativegeocoder
Run the following command to sync your project:
npx cap sync
In your code, import the NativeGeocoder
from @capgo/nativegeocoder
:
import { NativeGeocoder } from '@capgo/nativegeocoder';
The @capgo/nativegeocoder
plugin provides two main methods for geocoding:
Reverse geocoding is the process of converting geographic coordinates (latitude and longitude) into an address.
const reverseOptions = {
latitude: 37.7749,
longitude: -122.4194,
};
const address = NativeGeocoder.reverseGeocode(reverseOptions);
console.log(address);
The reverseGeocode
method takes an object with the latitude and longitude properties. It returns the address as a result.
Forward geocoding is the process of converting an address into geographic coordinates (latitude and longitude).
const forwardOptions = {
address: '1600 Amphitheatre Parkway, Mountain View, CA',
};
const coordinates = NativeGeocoder.forwardGeocode(forwardOptions);
console.log(coordinates);
The forwardGeocode
method takes an object with the address property. It returns the coordinates as a result.
The @capgo/nativegeocoder
package provides a simple and efficient way to perform geocoding in your Capacitor project. By following the steps outlined in this tutorial, you can easily integrate geocoding functionality into your application.