UNPKG

6.38 kBTypeScriptView Raw
1import { IonicNativePlugin } from '@ionic-native/core';
2import { Observable } from 'rxjs';
3export interface Coordinates {
4 /**
5 * a double representing the position's latitude in decimal degrees.
6 */
7 latitude: number;
8 /**
9 * A double representing the position's longitude in decimal degrees.
10 */
11 longitude: number;
12 /**
13 * A double representing the accuracy of the latitude and longitude properties,
14 * expressed in meters.
15 */
16 accuracy: number;
17 /**
18 * A double representing the position's altitude in metres, relative to sea
19 * level. This value can be null if the implementation cannot provide the data.
20 */
21 altitude: number;
22 /**
23 * A double representing the accuracy of the altitude expressed in meters.
24 * This value can be null.
25 */
26 altitudeAccuracy: number;
27 /**
28 * A double representing the direction in which the device is traveling. This
29 * value, specified in degrees, indicates how far off from heading true north
30 * the device is. 0 degrees represents true north, and the direction is
31 * determined clockwise (which means that east is 90 degrees and west is 270
32 * degrees). If speed is 0, heading is NaN. If the device is unable to provide
33 * heading information, this value is null.
34 */
35 heading: number;
36 /**
37 * A double representing the velocity of the device in meters per second.
38 * This value can be null.
39 */
40 speed: number;
41}
42export interface Geoposition {
43 /**
44 * A Coordinates object defining the current location
45 */
46 coords: Coordinates;
47 /**
48 * A timestamp representing the time at which the location was retrieved.
49 */
50 timestamp: number;
51}
52export interface PositionError {
53 /**
54 * A code that indicates the error that occurred
55 */
56 code: number;
57 /**
58 * A message that can describe the error that occurred
59 */
60 message: string;
61}
62export interface GeolocationOptions {
63 /**
64 * Is a positive long value indicating the maximum age in milliseconds of a
65 * possible cached position that is acceptable to return. If set to 0, it
66 * means that the device cannot use a cached position and must attempt to
67 * retrieve the real current position. If set to Infinity the device must
68 * return a cached position regardless of its age. Default: 0.
69 */
70 maximumAge?: number;
71 /**
72 * Is a positive long value representing the maximum length of time
73 * (in milliseconds) the device is allowed to take in order to return a
74 * position. The default value is Infinity, meaning that getCurrentPosition()
75 * won't return until the position is available.
76 */
77 timeout?: number;
78 /**
79 * Indicates the application would like to receive the best possible results.
80 * If true and if the device is able to provide a more accurate position, it
81 * will do so. Note that this can result in slower response times or increased
82 * power consumption (with a GPS chip on a mobile device for example). On the
83 * other hand, if false, the device can take the liberty to save resources by
84 * responding more quickly and/or using less power. Default: false.
85 * @type {boolean}
86 */
87 enableHighAccuracy?: boolean;
88}
89/**
90 * @name Geolocation
91 * @premier geolocation
92 * @description
93 * This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs.
94 *
95 * This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation.
96 *
97 * For iOS you have to add this configuration to your configuration.xml file
98 * ```xml
99 * <edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
100 * <string>We use your location for full functionality of certain app features.</string>
101 * </edit-config>
102 * ```
103 *
104 *
105 * @usage
106 *
107 * ```typescript
108 * import { Geolocation } from '@ionic-native/geolocation/ngx';
109 *
110 * ...
111 *
112 * constructor(private geolocation: Geolocation) {}
113 *
114 * ...
115 *
116 * this.geolocation.getCurrentPosition().then((resp) => {
117 * // resp.coords.latitude
118 * // resp.coords.longitude
119 * }).catch((error) => {
120 * console.log('Error getting location', error);
121 * });
122 *
123 * let watch = this.geolocation.watchPosition();
124 * watch.subscribe((data) => {
125 * // data can be a set of coordinates, or an error (if an error occurred).
126 * // data.coords.latitude
127 * // data.coords.longitude
128 * });
129 * ```
130 * @interfaces
131 * Coordinates
132 * Geoposition
133 * PositionError
134 * GeolocationOptions
135 */
136export declare class GeolocationOriginal extends IonicNativePlugin {
137 /**
138 * Get the device's current position.
139 *
140 * @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
141 * @returns {Promise<Geoposition>} Returns a Promise that resolves with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or rejects with an error.
142 */
143 getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition>;
144 /**
145 * Watch the current device's position. Clear the watch by unsubscribing from
146 * Observable changes.
147 *
148 * ```typescript
149 * const subscription = this.geolocation.watchPosition()
150 * .filter((p) => p.coords !== undefined) //Filter Out Errors
151 * .subscribe(position => {
152 * console.log(position.coords.longitude + ' ' + position.coords.latitude);
153 * });
154 *
155 * // To stop notifications
156 * subscription.unsubscribe();
157 * ```
158 *
159 * @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
160 * @returns {Observable<Geoposition | PositionError>} Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.
161 */
162 watchPosition(options?: GeolocationOptions): Observable<Geoposition | PositionError>;
163}
164
165export declare const Geolocation: GeolocationOriginal;
\No newline at end of file