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.
Have a look at the demo project for a working demo with the Ionic Framework and Ionic Native.
- 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)
nativegeocoder.reverseGeocode(success, failure, 52.5072095, 13.1452818);
function success(result) {
alert("The address is: \n\n" + result.street + " " + result.houseNumber + ", " + result.postalCode + " " + result.city + " " + result.district + " in " + result.countryName + " - " + result.countryCode);
}
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)
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));
}