-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nativegeocoder): add NativeGeocoder plugin (#800)
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |