Skip to content

Commit

Permalink
feat(nativegeocoder): change return type to array and add options pa…
Browse files Browse the repository at this point in the history
…ram (#2319)

* feat(nativegeocoder): add NativeGeocoder plugin

* add district

* update NativeGeocoderReverseResult & refactor code

* delete plugins

* delete index.ts

* type(feat): change return type to array and add options param

* Add 'defaultLocale' to options Object

* let options be optional
  • Loading branch information
sebastianbaar authored and danielsogl committed Jun 23, 2018
1 parent 1dc48e9 commit 9f662b6
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions src/@ionic-native/plugins/native-geocoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@ import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
*
* @usage
* ```typescript
* import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult } from '@ionic-native/native-geocoder';
* import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder';
*
* constructor(private nativeGeocoder: NativeGeocoder) { }
*
* ...
*
* this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818)
* .then((result: NativeGeocoderReverseResult) => console.log(JSON.stringify(result)))
* let options: NativeGeocoderOptions = {
* useLocale: true,
* maxResults: 5
* };
*
* this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
* .then((result: NativeGeocoderReverseResult[]) => console.log(JSON.stringify(result[0])))
* .catch((error: any) => console.log(error));
*
* this.nativeGeocoder.forwardGeocode('Berlin')
* .then((coordinates: NativeGeocoderForwardResult) => console.log('The coordinates are latitude=' + coordinates.latitude + ' and longitude=' + coordinates.longitude))
* this.nativeGeocoder.forwardGeocode('Berlin', options)
* .then((coordinates: NativeGeocoderForwardResult[]) => console.log('The coordinates are latitude=' + coordinates[0].latitude + ' and longitude=' + coordinates[0].longitude))
* .catch((error: any) => console.log(error));
* ```
* @interfaces
* NativeGeocoderReverseResult
* NativeGeocoderForwardResult
* NativeGeocoderOptions
*/
@Plugin({
pluginName: 'NativeGeocoder',
Expand All @@ -40,22 +46,24 @@ export class NativeGeocoder extends IonicNativePlugin {
* Reverse geocode a given latitude and longitude to find location address
* @param latitude {number} The latitude
* @param longitude {number} The longitude
* @return {Promise<NativeGeocoderReverseResult>}
* @param options {NativeGeocoderOptions} The options
* @return {Promise<NativeGeocoderReverseResult[]>}
*/
@Cordova({
callbackOrder: 'reverse'
})
reverseGeocode(latitude: number, longitude: number): Promise<NativeGeocoderReverseResult[]> { return; }
reverseGeocode(latitude: number, longitude: number, options?: NativeGeocoderOptions): Promise<NativeGeocoderReverseResult[]> { return; }

/**
* Forward geocode a given address to find coordinates
* @param addressString {string} The address to be geocoded
* @return {Promise<NativeGeocoderForwardResult>}
* @param options {NativeGeocoderOptions} The options
* @return {Promise<NativeGeocoderForwardResult[]>}
*/
@Cordova({
callbackOrder: 'reverse'
})
forwardGeocode(addressString: string): Promise<NativeGeocoderForwardResult[]> { return; }
forwardGeocode(addressString: string, options?: NativeGeocoderOptions): Promise<NativeGeocoderForwardResult[]> { return; }
}

/**
Expand Down Expand Up @@ -116,3 +124,25 @@ export interface NativeGeocoderForwardResult {
*/
longitude: string;
}

/**
* Options for reverse and forward geocoding.
*/
export interface NativeGeocoderOptions {
/**
* The locale to use when returning the address information.
* If set to 'false' the locale will always be 'en_US'.
* Default is 'true'
*/
useLocale: boolean;
/**
* The default locale to use when returning the address information.
* e.g.: 'fa-IR' or 'de_DE'.
*/
defaultLocale?: string;
/**
* The maximum number of result to return (max is 5).
* Default is 1
*/
maxResults: number;
}

0 comments on commit 9f662b6

Please sign in to comment.