Skip to content

Commit

Permalink
feat(nativegeocoder): add NativeGeocoder plugin (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Baar authored and ihadeed committed Jan 20, 2017
1 parent db55342 commit 911537b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -293,6 +295,7 @@ window['IonicNative'] = {
Mixpanel,
MusicControls,
NativeAudio,
NativeGeocoder,
NativePageTransitions,
NativeStorage,
Network,
Expand Down
90 changes: 90 additions & 0 deletions src/plugins/native-geocoder.ts
Original file line number Diff line number Diff line change
@@ -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<any>}
*/
@Cordova()
static reverseGeocode(latitude: number, longitude: number): Promise<ReverseResult> { return; }

/**
* Forward geocode a given address to find coordinates
* @param addressString {string} The address to be geocoded
* @return {Promise<any>}
*/
@Cordova()
static forwardGeocode(addressString: string): Promise<ForwardResult> { 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;
}

0 comments on commit 911537b

Please sign in to comment.