diff --git a/src/index.ts b/src/index.ts index f771d60e1..ed004c6cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,6 +70,7 @@ import { LocalNotifications } from './plugins/localnotifications'; import { LocationAccuracy } from './plugins/location-accuracy'; import { MediaCapture } from './plugins/media-capture'; import { NativeAudio } from './plugins/native-audio'; +import { NativeGeocoder } from './plugins/native-geocoder'; import { NativePageTransitions } from './plugins/native-page-transitions'; import { NativeStorage } from './plugins/nativestorage'; import { Market } from './plugins/market'; @@ -183,6 +184,7 @@ export * from './plugins/media-capture'; export * from './plugins/mixpanel'; export * from './plugins/music-controls'; export * from './plugins/native-audio'; +export * from './plugins/native-geocoder'; export * from './plugins/native-page-transitions'; export * from './plugins/nativestorage'; export * from './plugins/network'; @@ -293,6 +295,7 @@ window['IonicNative'] = { Mixpanel, MusicControls, NativeAudio, + NativeGeocoder, NativePageTransitions, NativeStorage, Network, diff --git a/src/plugins/native-geocoder.ts b/src/plugins/native-geocoder.ts new file mode 100644 index 000000000..c5d0450cf --- /dev/null +++ b/src/plugins/native-geocoder.ts @@ -0,0 +1,90 @@ +import { Plugin, Cordova } from './plugin'; + +/** + * @name NativeGeocoder + * @description + * Cordova plugin for native forward and reverse geocoding + * + * @usage + * ```typescript + * import { NativeGeocoder } from 'ionic-native'; + * + * NativeGeocoder.reverseGeocode(52.5072095, 13.1452818) + * .then((result: ReverseResult) => console.log("The address is " + result.address + " in " + result.countryCode)) + * .catch((error: any) => console.log(error)); + * + * NativeGeocoder.forwardGeocode("Berlin") + * .then((coordinates: ForwardResult) => console.log("The coordinates are latitude=" + coordinates.latitude + " and longitude=" + coordinates.longitude)) + * .catch((error: any) => console.log(error)); + * ``` + */ +@Plugin({ + name: 'NativeGeocoder', + plugin: 'cordova-plugin-nativegeocoder', + pluginRef: 'nativegeocoder', + repo: 'https://github.com/sebastianbaar/cordova-plugin-nativegeocoder', + platforms: ['iOS', 'Android'] +}) +export class NativeGeocoder { + + /** + * Reverse geocode a given latitude and longitude to find location address + * @param latitude {number} The latitude + * @param longitude {number} The longitude + * @return {Promise} + */ + @Cordova() + static reverseGeocode(latitude: number, longitude: number): Promise { return; } + + /** + * Forward geocode a given address to find coordinates + * @param addressString {string} The address to be geocoded + * @return {Promise} + */ + @Cordova() + static forwardGeocode(addressString: string): Promise { return; } + +} + +/** + * Encapsulates format information about a reverse geocoding result. + */ +export interface ReverseResult { + /** + * The street. + */ + street: string; + /** + * The house number. + */ + houseNumber: string; + /** + * The postal code. + */ + postalCode: string; + /** + * The city. + */ + city: string; + /** + * The country name. + */ + countryName: string; + /** + * The country code. + */ + countryCode: string; +} +/** + * Encapsulates format information about a forward geocoding result. + */ +export interface ForwardResult { + /** + * The latitude. + */ + latitude: string; + /** + * The longitude. + */ + longitude: string; +}