zrelyydereva / cordova-plugin-nativegeocoder

Cordova plugin for native forward and reverse geocoding

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cordova NativeGeocoder plugin

Call nativegeocoder.reverseGeocode() to transform a latitude and longitude into an address or nativegeocoder.forwardGeocode() to transform an address into a latitude and longitude using iOS CoreLocation service and Android Geocoder class.

No need for creating API keys or querying external APIs

Installation

cordova plugin add cordova-plugin-nativegeocoder

The iOS part is written in Swift 3 and the Swift support plugin is configured as a dependency.

Configuration

You can also configure the following variable to customize the iOS location plist entry

  • LOCATION_WHEN_IN_USE_DESCRIPTION for NSLocationWhenInUseUsageDescription (defaults to "Use geocoder service")

Supported Platforms

  • iOS
  • Android (works only on native devices)

Methods

  • nativegeocoder.reverseGeocode
  • nativegeocoder.forwardGeocode

nativegeocoder.reverseGeocode

Reverse geocode a given latitude and longitude to find location address.

nativegeocoder.reverseGeocode(successCallback, errorCallback, latitude, longitude);

Parameters

  • latitude: The latitude. (Double)
  • longitude: The longtitude. (Double)

Result Object

https://developer.apple.com/documentation/corelocation/clplacemark https://developer.android.com/reference/android/location/Address.html

  • countryCode
  • postalCode
  • administrativeArea
  • subAdministrativeArea
  • locality
  • subLocality
  • thoroughfare
  • subThoroughfare

Example

nativegeocoder.reverseGeocode(success, failure, 52.5072095, 13.1452818);
function success(result) {
  alert("The address is: \n\n" + JSON.stringify(result));
}
function failure(err) {
  alert(JSON.stringify(err));
}

nativegeocoder.forwardGeocode

Forward geocode a given address to find coordinates.

nativegeocoder.forwardGeocode(successCallback, errorCallback, addressString);

Parameters

  • addressString: The address to be geocoded. (String)

Result Object

  • latitude
  • longitude

Example

nativegeocoder.forwardGeocode(success, failure, "Berlin");
function success(coordinates) {
  alert("The coordinates are latitude = " + coordinates.latitude + " and longitude = " + coordinates.longitude);
}
function failure(err) {
  alert(JSON.stringify(err));
}

About

Cordova plugin for native forward and reverse geocoding

License:MIT License


Languages

Language:Java 51.4%Language:Swift 45.4%Language:JavaScript 2.8%Language:Objective-C 0.3%