Native Geocoder
Cordova plugin for native forward and reverse geocoding
Repo: https://github.com/sebastianbaar/cordova-plugin-nativegeocoder
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-nativegeocoder $ npm install --save @ionic-native/native-geocoder@4
- Add this plugin to your app's module
Supported platforms
- iOS
- Android
Usage
import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder';
constructor(private nativeGeocoder: NativeGeocoder) { }
...
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderReverseResult[]) => console.log(JSON.stringify(result[0])))
.catch((error: any) => console.log(error));
this.nativeGeocoder.forwardGeocode('Berlin', options)
.then((coordinates: NativeGeocoderForwardResult[]) => console.log('The coordinates are latitude=' + coordinates[0].latitude + ' and longitude=' + coordinates[0].longitude))
.catch((error: any) => console.log(error));
Instance Members
reverseGeocode(latitude, longitude, options)
Reverse geocode a given latitude and longitude to find location address
Param | Type | Details |
---|---|---|
latitude |
number
|
The latitude |
longitude |
number
|
The longitude |
options |
NativeGeocoderOptions
|
The options |
Returns: Promise<NativeGeocoderReverseResult[]>
forwardGeocode(addressString, options)
Forward geocode a given address to find coordinates
Param | Type | Details |
---|---|---|
addressString |
string
|
The address to be geocoded |
options |
NativeGeocoderOptions
|
The options |
Returns: Promise<NativeGeocoderForwardResult[]>
NativeGeocoderReverseResult
Param | Type | Details |
---|---|---|
countryCode |
string
|
The country code. |
countryName |
string
|
The country name. |
postalCode |
string
|
The postal code. |
administrativeArea |
string
|
The administrativeArea. |
subAdministrativeArea |
string
|
The subAdministrativeArea. |
locality |
string
|
The locality. |
subLocality |
string
|
The subLocality. |
thoroughfare |
string
|
The thoroughfare. |
subThoroughfare |
string
|
The subThoroughfare. |
NativeGeocoderForwardResult
Param | Type | Details |
---|---|---|
latitude |
string
|
The latitude. |
longitude |
string
|
The longitude. |
NativeGeocoderOptions
Param | Type | Details |
---|---|---|
useLocale |
boolean
|
The locale to use when returning the address information. If set to 'false' the locale will always be 'en_US'. Default is 'true' |
defaultLocale |
string
|
The default locale to use when returning the address information. e.g.: 'fa-IR' or 'de_DE'. (optional) |
maxResults |
number
|
The maximum number of result to return (max is 5). Default is 1 |