UNPKG

15.7 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2export interface BackgroundGeolocationResponse {
3 /**
4 * ID of location as stored in DB (or null)
5 */
6 locationId: number;
7 /**
8 * Service provider
9 */
10 serviceProvider: string;
11 /**
12 * true if location recorded as part of debug
13 */
14 debug: boolean;
15 /**
16 * UTC time of this fix, in milliseconds since January 1, 1970.
17 */
18 time: number;
19 /**
20 * latitude, in degrees.
21 */
22 latitude: number;
23 /**
24 * longitude, in degrees.
25 */
26 longitude: number;
27 /**
28 * estimated accuracy of this location, in meters.
29 */
30 accuracy: number;
31 /**
32 * speed if it is available, in meters/second over ground.
33 */
34 speed: number;
35 /**
36 * altitude if available, in meters above the WGS 84 reference ellipsoid.
37 */
38 altitude: number;
39 /**
40 * accuracy of the altitude if available.
41 */
42 altitudeAccuracy: number;
43 /**
44 * bearing, in degrees.
45 */
46 bearing: number;
47 /**
48 * A Coordinates object defining the current location
49 */
50 coords: Coordinates;
51 /**
52 * A timestamp representing the time at which the location was retrieved.
53 */
54 timestamp: number;
55}
56export interface BackgroundGeolocationConfig {
57 /**
58 * Desired accuracy in meters. Possible values [0, 10, 100, 1000]. The lower
59 * the number, the more power devoted to GeoLocation resulting in higher
60 * accuracy readings. 1000 results in lowest power drain and least accurate
61 * readings. @see Apple docs (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy)
62 */
63 desiredAccuracy: number;
64 /**
65 * Stationary radius in meters. When stopped, the minimum distance the device
66 * must move beyond the stationary location for aggressive background-tracking
67 * to engage.
68 */
69 stationaryRadius: number;
70 /**
71 * When enabled, the plugin will emit sounds for life-cycle events of
72 * background-geolocation! See debugging sounds table.
73 */
74 debug?: boolean;
75 /**
76 * The minimum distance (measured in meters) a device must move horizontally
77 * before an update event is generated. @see Apple docs. (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter)
78 */
79 distanceFilter: number;
80 /**
81 * IOS, ANDROID ONLY
82 * Enable this in order to force a stop() when the application terminated
83 * (e.g. on iOS, double-tap home button, swipe away the app).o
84 *
85 * Defaults to true
86 */
87 stopOnTerminate?: boolean;
88 /**
89
90 * ANDROID ONLY
91
92 * Start background service on device boot.
93
94 *
95 * Defaults to false
96
97 */
98 startOnBoot?: boolean;
99 /**
100
101 * ANDROID ONLY
102
103 * If false location service will not be started in foreground and no notification will be shown.
104 *
105 * Defaults to true
106
107 */
108 startForeground?: boolean;
109 /**
110 * ANDROID, WP8 ONLY
111 * When using BackgroundGeolocation.LocationProvider.ANDROID_DISTANCE_FILTER_PROVIDER:
112 * The minimum time interval between location updates in milliseconds.
113 * @see Android docs (http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent))
114 * and the MS doc (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.reportinterval)
115 * for more information
116 * When using BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER:
117 * Rate in milliseconds at which your app prefers to receive location updates.
118 * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getInterval())
119 */
120 interval?: number;
121 /**
122 * ANDROID ONLY
123 * Custom notification title in the drawer.
124 */
125 notificationTitle?: string;
126 /**
127 * ANDROID ONLY
128 * Custom notification text in the drawer.
129 */
130 notificationText?: string;
131 /**
132 * ANDROID ONLY
133 * The accent color to use for notification. Eg. #4CAF50.
134 */
135 notificationIconColor?: string;
136 /**
137
138 * ANDROID ONLY
139
140 * The filename of a custom notification icon. See android quirks.
141
142 * NOTE: Only available for API Level >=21.
143
144 */
145 notificationIconLarge?: string;
146 /**
147
148 * ANDROID ONLY
149
150 * The filename of a custom notification icon. See android quirks.
151
152 * NOTE: Only available for API Level >=21.
153
154 */
155 notificationIconSmall?: string;
156 /**
157 * ANDROID ONLY
158 * Set location service provider @see wiki (https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers)
159 */
160 locationProvider?: number;
161 /**
162 * IOS ONLY
163 * [AutomotiveNavigation, OtherNavigation, Fitness, Other] Presumably,
164 * this affects iOS GPS algorithm. @see Apple docs for more information
165 * (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType)
166 */
167 activityType?: string;
168 /**
169
170 * IOS ONLY
171
172 * Pauses location updates when app is paused
173
174 *
175 * Defaults to true
176
177 */
178 pauseLocationUpdates?: boolean;
179 /**
180
181 * Server url where to send HTTP POST with recorded locations
182
183 * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting
184
185 */
186 url?: string;
187 /**
188
189 * Server url where to send fail to post locations
190
191 * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting
192
193 */
194 syncUrl?: string;
195 /**
196 * Specifies how many previously failed locations will be sent to server at once
197
198 *
199 * Defaults to 100
200
201 */
202 syncThreshold?: number;
203 /**
204
205 * Optional HTTP headers sent along in HTTP request
206
207 */
208 httpHeaders?: any;
209 /**
210 * IOS ONLY
211
212 * Switch to less accurate significant changes and region monitory when in background (default)
213 *
214 * Defaults to 100
215
216 */
217 saveBatteryOnBackground?: boolean;
218 /**
219
220 * Limit maximum number of locations stored into db
221
222 *
223 * Defaults to 10000
224
225 */
226 maxLocations?: number;
227 /**
228 * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
229 *
230 * Fastest rate in milliseconds at which your app can handle location updates.
231 * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getFastestInterval())
232 */
233 fastestInterval?: number;
234 /**
235 * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
236 *
237 * Rate in milliseconds at which activity recognition occurs. Larger values will result in fewer activity detections while improving battery life.
238 */
239 activitiesInterval?: number;
240 /**
241 * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
242 *
243 * stop() is forced, when the STILL activity is detected (default is true)
244 */
245 stopOnStillActivity?: boolean;
246}
247/**
248 * @name BackgroundGeolocation
249 * @description
250 * This plugin provides foreground and background geolocation with battery-saving "circular region monitoring" and "stop detection". For
251 * more detail, please see https://github.com/mauron85/cordova-plugin-background-geolocation
252 *
253 * @usage
254 *
255 * ```typescript
256 * import { BackgroundGeolocation } from 'ionic-native';
257 *
258 *
259 * // When device is ready :
260 * platform.ready().then(() => {
261 * // IMPORTANT: BackgroundGeolocation must be called within app.ts and or before Geolocation. Otherwise the platform will not ask you for background tracking permission.
262 *
263 * // BackgroundGeolocation is highly configurable. See platform specific configuration options
264 * let config = {
265 * desiredAccuracy: 10,
266 * stationaryRadius: 20,
267 * distanceFilter: 30,
268 * debug: true, // enable this hear sounds for background-geolocation life-cycle.
269 * stopOnTerminate: false, // enable this to clear background location settings when the app terminates
270 * };
271 *
272 * BackgroundGeolocation.configure((location) => {
273 console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
274
275 // IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
276 // and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
277 // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
278 BackgroundGeolocation.finish(); // FOR IOS ONLY
279
280 * }, (error) => {
281 * console.log('BackgroundGeolocation error');
282 * }, config);
283 *
284 * // Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
285 * BackgroundGeolocation.start();
286 * })
287 *
288 * // If you wish to turn OFF background-tracking, call the #stop method.
289 * BackgroundGeolocation.stop();
290 *
291 * ```
292 * @interfaces
293 * BackgroundGeolocationResponse
294 * BackgroundGeolocationConfig
295 */
296export declare class BackgroundGeolocation {
297 /**
298
299 * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers
300
301 *
302 * Possible values:
303 * ANDROID_DISTANCE_FILTER_PROVIDER: 0,
304
305 * ANDROID_ACTIVITY_PROVIDER: 1
306
307 *
308 * @enum {number}
309
310 */
311 static LocationProvider: any;
312 /**
313 * Desired accuracy in meters. Possible values [0, 10, 100, 1000].
314
315 * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings.
316
317 * 1000 results in lowest power drain and least accurate readings.
318
319 *
320 * Possible values:
321 * HIGH: 0
322
323 * MEDIUM: 10
324
325 * LOW: 100
326
327 * PASSIVE: 1000
328 *
329 * enum {number}
330
331 */
332 static Accuracy: any;
333 /**
334
335 * Used in the switchMode function
336
337 *
338 * Possible values:
339 * BACKGROUND: 0
340 * FOREGROUND: 1
341
342 *
343 * @enum {number}
344
345 */
346 static Mode: any;
347 /**
348 * Configure the plugin.
349 *
350 * @param options {BackgroundGeolocationConfig} options An object of type Config
351 * @return {Observable<any>}
352 */
353 static configure(options: BackgroundGeolocationConfig): Observable<any>;
354 /**
355 * Turn ON the background-geolocation system.
356 * The user will be tracked whenever they suspend the app.
357 * @returns {Promise<any>}
358 */
359 static start(): Promise<any>;
360 /**
361 * Turn OFF background-tracking
362 * @returns {Promise<any>}
363 */
364 static stop(): Promise<any>;
365 /**
366 * Inform the native plugin that you're finished, the background-task may be completed
367 * @returns {Promise<any>}
368 */
369 static finish(): Promise<any>;
370 /**
371 * Force the plugin to enter "moving" or "stationary" state
372 * @param isMoving {boolean}
373 * @returns {Promise<any>}
374 */
375 static changePace(isMoving: boolean): Promise<any>;
376 /**
377 * Setup configuration
378 * @param options {BackgroundGeolocationConfig}
379 * @returns {Promise<any>}
380 */
381 static setConfig(options: BackgroundGeolocationConfig): Promise<any>;
382 /**
383 * Returns current stationaryLocation if available. null if not
384 * @returns {Promise<Location>}
385 */
386 static getStationaryLocation(): Promise<BackgroundGeolocationResponse>;
387 /**
388 * Add a stationary-region listener. Whenever the devices enters "stationary-mode",
389 * your #success callback will be executed with #location param containing #radius of region
390 * @returns {Promise<any>}
391 */
392 static onStationary(): Promise<any>;
393 /**
394 * Check if location is enabled on the device
395 * @returns {Promise<number>} Returns a promise with int argument that takes values 0, 1 (true).
396 */
397 static isLocationEnabled(): Promise<number>;
398 /**
399 * Display app settings to change permissions
400 */
401 static showAppSettings(): void;
402 /**
403 * Display device location settings
404 */
405 static showLocationSettings(): void;
406 /**
407 * Method can be used to detect user changes in location services settings.
408 * If user enable or disable location services then success callback will be executed.
409 * In case or error (SettingNotFoundException) fail callback will be executed.
410 * @returns {Promise<boolean>}
411 */
412 static watchLocationMode(): Promise<boolean>;
413 /**
414 * Stop watching for location mode changes.
415 * @returns {Promise<any>}
416 */
417 static stopWatchingLocationMode(): Promise<any>;
418 /**
419 * Method will return all stored locations.
420 * Locations are stored when:
421 * - config.stopOnTerminate is false and main activity was killed
422 * by the system
423 * or
424 * - option.debug is true
425 * @returns {Promise<any>}
426 */
427 static getLocations(): Promise<any>;
428 /**
429
430 * Method will return locations, which has not been yet posted to server. NOTE: Locations does contain locationId.
431
432 * @returns {Promise<any>}
433 */
434 static getValidLocations(): Promise<any>;
435 /**
436 * Delete stored location by given locationId.
437 * @param locationId {number}
438 * @returns {Promise<any>}
439 */
440 static deleteLocation(locationId: number): Promise<any>;
441 /**
442 * Delete all stored locations.
443 * @returns {Promise<any>}
444 */
445 static deleteAllLocations(): Promise<any>;
446 /**
447 * Normally plugin will handle switching between BACKGROUND and FOREGROUND mode itself.
448 * Calling switchMode you can override plugin behavior and force plugin to switch into other mode.
449 *
450 * In FOREGROUND mode plugin uses iOS local manager to receive locations and behavior is affected by option.desiredAccuracy and option.distanceFilter.
451 * In BACKGROUND mode plugin uses significant changes and region monitoring to receive locations and uses option.stationaryRadius only.
452
453 *
454 * BackgroundGeolocation.Mode.FOREGROUND
455 * BackgroundGeolocation.Mode.BACKGROUND
456
457 **
458 * @param modeId {number}
459 * @returns {Promise<any>}
460 */
461 static switchMode(modeId: number): Promise<any>;
462 /**
463
464 * Return all logged events. Useful for plugin debugging. Parameter limit limits number of returned entries.
465
466 * @see https://github.com/mauron85/cordova-plugin-background-geolocation/tree/v2.2.1#debugging for more information.
467
468 *
469 * @param limit {number} Limits the number of entries
470
471 * @returns {Promise<any>}
472 */
473 static getLogEntries(limit: number): Promise<any>;
474}