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
cordova plugin add cordova-plugin-nativegeocoder
The iOS part is written in Swift 3 and the Swift support plugin is configured as a dependency.
You can also configure the following variable to customize the iOS location plist entry
LOCATION_WHEN_IN_USE_DESCRIPTION
forNSLocationWhenInUseUsageDescription
(defaults to "Use geocoder service")
- iOS
- Android (works only on native devices)
- nativegeocoder.reverseGeocode
- nativegeocoder.forwardGeocode
Reverse geocode a given latitude and longitude to find location address.
nativegeocoder.reverseGeocode(successCallback, errorCallback, latitude, longitude);
- latitude: The latitude. (Double)
- longitude: The longtitude. (Double)
https://developer.apple.com/documentation/corelocation/clplacemark https://developer.android.com/reference/android/location/Address.html
- countryCode
- postalCode
- administrativeArea
- subAdministrativeArea
- locality
- subLocality
- thoroughfare
- subThoroughfare
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));
}
Forward geocode a given address to find coordinates.
nativegeocoder.forwardGeocode(successCallback, errorCallback, addressString);
- addressString: The address to be geocoded. (String)
- latitude
- longitude
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));
}