2016-07-08 06:34:43 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
|
2016-05-13 07:26:05 +08:00
|
|
|
|
|
|
|
declare var window;
|
|
|
|
|
|
|
|
|
|
|
|
export interface Location {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ID of location as stored in DB (or null)
|
|
|
|
*/
|
|
|
|
locationId: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Service provider
|
|
|
|
*/
|
|
|
|
serviceProvider: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* true if location recorded as part of debug
|
|
|
|
*/
|
2016-06-01 18:56:04 +08:00
|
|
|
debug: boolean;
|
2016-05-13 07:26:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UTC time of this fix, in milliseconds since January 1, 1970.
|
|
|
|
*/
|
|
|
|
time: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* latitude, in degrees.
|
|
|
|
*/
|
|
|
|
latitude: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* longitude, in degrees.
|
|
|
|
*/
|
|
|
|
longitude: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* estimated accuracy of this location, in meters.
|
|
|
|
*/
|
|
|
|
accuracy: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* speed if it is available, in meters/second over ground.
|
|
|
|
*/
|
|
|
|
speed: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* altitude if available, in meters above the WGS 84 reference ellipsoid.
|
|
|
|
*/
|
|
|
|
altitude: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bearing, in degrees.
|
|
|
|
*/
|
|
|
|
bearing: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Coordinates object defining the current location
|
|
|
|
*/
|
|
|
|
coords: Coordinates;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A timestamp representing the time at which the location was retrieved.
|
|
|
|
*/
|
|
|
|
timestamp: number;
|
|
|
|
}
|
|
|
|
|
2016-05-13 21:58:43 +08:00
|
|
|
export interface Config {
|
2016-05-13 07:26:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Desired accuracy in meters. Possible values [0, 10, 100, 1000]. The lower
|
|
|
|
* the number, the more power devoted to GeoLocation resulting in higher
|
|
|
|
* accuracy readings. 1000 results in lowest power drain and least accurate
|
|
|
|
* readings. @see Apple docs (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy)
|
|
|
|
*/
|
|
|
|
desiredAccuracy: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stationary radius in meters. When stopped, the minimum distance the device
|
|
|
|
* must move beyond the stationary location for aggressive background-tracking
|
|
|
|
* to engage.
|
|
|
|
*/
|
|
|
|
stationaryRadius: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When enabled, the plugin will emit sounds for life-cycle events of
|
|
|
|
* background-geolocation! See debugging sounds table.
|
|
|
|
*/
|
|
|
|
debug: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The minimum distance (measured in meters) a device must move horizontally
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
distanceFilter: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IOS, ANDROID ONLY
|
|
|
|
* Enable this in order to force a stop() when the application terminated
|
|
|
|
* (e.g. on iOS, double-tap home button, swipe away the app).
|
|
|
|
*/
|
|
|
|
stopOnTerminate?: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID, WP8 ONLY
|
|
|
|
* The minimum time interval between location updates in seconds.
|
|
|
|
* @see Android docs (http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent))
|
|
|
|
* and the MS doc (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.reportinterval)
|
|
|
|
* for more information
|
|
|
|
*/
|
|
|
|
locationTimeout?: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Custom notification title in the drawer.
|
|
|
|
*/
|
|
|
|
notificationTitle?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Custom notification text in the drawer.
|
|
|
|
*/
|
|
|
|
notificationText?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* The accent color to use for notification. Eg. #4CAF50.
|
|
|
|
*/
|
|
|
|
notificationIconColor?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* The filename of a custom notification icon. See android quirks.
|
|
|
|
* NOTE: Only available for API Level >=21.
|
|
|
|
*/
|
|
|
|
notificationIcon?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Set location service provider @see wiki (https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers)
|
|
|
|
*/
|
|
|
|
locationService?: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IOS ONLY
|
|
|
|
* [AutomotiveNavigation, OtherNavigation, Fitness, Other] Presumably,
|
|
|
|
* this affects iOS GPS algorithm. @see Apple docs for more information
|
|
|
|
* (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType)
|
|
|
|
*/
|
|
|
|
activityType?: string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name BackgroundGeolocation
|
|
|
|
* @description
|
|
|
|
* This plugin provides foreground and background geolocation with battery-saving "circular region monitoring" and "stop detection". For
|
|
|
|
* more detail, please see https://github.com/mauron85/cordova-plugin-background-geolocation
|
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* import {BackgroundGeolocation} from 'ionic-native';
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // When device is ready :
|
|
|
|
* platform.ready().then(() => {
|
|
|
|
*
|
2016-05-13 21:58:43 +08:00
|
|
|
* // BackgroundGeolocation is highly configurable. See platform specific configuration options
|
2016-06-09 14:35:03 +08:00
|
|
|
* let config = {
|
|
|
|
* desiredAccuracy: 10,
|
|
|
|
* stationaryRadius: 20,
|
|
|
|
* distanceFilter: 30,
|
|
|
|
* debug: true, // enable this hear sounds for background-geolocation life-cycle.
|
|
|
|
* stopOnTerminate: false, // enable this to clear background location settings when the app terminates
|
|
|
|
* };
|
2016-07-08 06:34:43 +08:00
|
|
|
*
|
2016-06-09 14:35:03 +08:00
|
|
|
* BackgroundGeolocation.configure(config)
|
|
|
|
* .then((location) => {
|
2016-05-13 21:58:43 +08:00
|
|
|
* console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
|
2016-05-15 09:15:51 +08:00
|
|
|
*
|
|
|
|
* // IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
|
|
|
|
* // and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
|
|
|
|
* // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
|
2016-06-09 14:35:03 +08:00
|
|
|
* BackgroundGeolocation.finish(); // FOR IOS ONLY
|
|
|
|
* })
|
|
|
|
* .catch((error) => {
|
2016-05-13 21:58:43 +08:00
|
|
|
* console.log('BackgroundGeolocation error');
|
2016-06-09 14:35:03 +08:00
|
|
|
* });
|
2016-05-13 07:26:05 +08:00
|
|
|
*
|
|
|
|
* // Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
|
2016-05-13 21:58:43 +08:00
|
|
|
* BackgroundGeolocation.start();
|
2016-05-13 07:26:05 +08:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // If you wish to turn OFF background-tracking, call the #stop method.
|
2016-05-13 21:58:43 +08:00
|
|
|
* BackgroundGeolocation.stop();
|
2016-05-13 07:26:05 +08:00
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Plugin({
|
|
|
|
plugin: 'cordova-plugin-mauron85-background-geolocation',
|
2016-07-12 05:42:11 +08:00
|
|
|
pluginRef: 'backgroundGeolocation',
|
2016-06-11 22:49:03 +08:00
|
|
|
repo: 'https://github.com/mauron85/cordova-plugin-background-geolocation',
|
|
|
|
platforms: ['iOS', 'Android', 'Windows Phone 8']
|
2016-05-13 07:26:05 +08:00
|
|
|
})
|
2016-05-13 21:58:43 +08:00
|
|
|
export class BackgroundGeolocation {
|
2016-05-13 07:26:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure the plugin.
|
|
|
|
* Success callback will be called with one argument - Location object, which tries to mimic w3c Coordinates interface.
|
|
|
|
* See http://dev.w3.org/geo/api/spec-source.html#coordinates_interface
|
|
|
|
* Callback to be executed every time a geolocation is recorded in the background.
|
|
|
|
*
|
|
|
|
* Fail callback to be executed every time a geolocation error occurs.
|
|
|
|
*
|
2016-05-15 09:15:51 +08:00
|
|
|
* Options a json object of type Config
|
2016-05-13 07:26:05 +08:00
|
|
|
*/
|
2016-05-15 10:47:35 +08:00
|
|
|
@Cordova({
|
|
|
|
callbackOrder: 'reverse'
|
|
|
|
})
|
2016-05-15 09:15:51 +08:00
|
|
|
static configure(options: Config): Promise<Location> { return; }
|
2016-05-13 07:26:05 +08:00
|
|
|
|
2016-05-13 21:58:43 +08:00
|
|
|
|
|
|
|
/**
|
2016-05-15 09:15:51 +08:00
|
|
|
* Turn ON the background-geolocation system.
|
2016-05-13 21:58:43 +08:00
|
|
|
* The user will be tracked whenever they suspend the app.
|
|
|
|
*/
|
2016-05-15 09:15:51 +08:00
|
|
|
@Cordova()
|
2016-05-18 05:34:14 +08:00
|
|
|
static start(): Promise<any> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn OFF background-tracking
|
|
|
|
*/
|
2016-05-15 09:15:51 +08:00
|
|
|
@Cordova()
|
2016-05-15 10:47:35 +08:00
|
|
|
static stop(): Promise<any> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-13 21:58:43 +08:00
|
|
|
/**
|
|
|
|
* Inform the native plugin that you're finished, the background-task may be completed
|
2016-05-18 05:34:14 +08:00
|
|
|
* NOTE: IOS, WP only
|
2016-05-13 21:58:43 +08:00
|
|
|
*/
|
2016-05-15 09:15:51 +08:00
|
|
|
@Cordova()
|
2016-05-15 10:47:35 +08:00
|
|
|
static finish() { }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force the plugin to enter "moving" or "stationary" state
|
2016-05-18 05:34:14 +08:00
|
|
|
* NOTE: IOS, WP only
|
2016-05-13 21:58:43 +08:00
|
|
|
*/
|
2016-05-15 09:15:51 +08:00
|
|
|
@Cordova()
|
2016-05-15 10:47:35 +08:00
|
|
|
static changePace(isMoving: boolean) { }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup configuration
|
|
|
|
*/
|
2016-05-15 10:47:35 +08:00
|
|
|
@Cordova({
|
|
|
|
callbackOrder: 'reverse'
|
|
|
|
})
|
|
|
|
static setConfig(options: Config): Promise<any> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Returns current stationaryLocation if available. null if not
|
|
|
|
* NOTE: IOS, WP only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getStationaryLocation(): Promise<Location> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Add a stationary-region listener. Whenever the devices enters "stationary-mode",
|
|
|
|
* your #success callback will be executed with #location param containing #radius of region
|
|
|
|
* NOTE: IOS, WP only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static onStationary(): Promise<any> { return; }
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-13 21:58:43 +08:00
|
|
|
/**
|
2016-05-15 09:15:51 +08:00
|
|
|
* Check if location is enabled on the device
|
2016-05-15 10:47:35 +08:00
|
|
|
* @returns {Promise<number>} Returns a promise with int argument that takes values 0, 1 (true).
|
2016-05-18 05:34:14 +08:00
|
|
|
* NOTE: ANDROID only
|
2016-05-13 21:58:43 +08:00
|
|
|
*/
|
2016-05-15 09:15:51 +08:00
|
|
|
@Cordova()
|
2016-05-15 10:47:35 +08:00
|
|
|
static isLocationEnabled(): Promise<number> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-15 09:15:51 +08:00
|
|
|
/**
|
|
|
|
* Display device location settings
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-05-15 10:47:35 +08:00
|
|
|
static showLocationSettings() { }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Method can be used to detect user changes in location services settings.
|
|
|
|
* If user enable or disable location services then success callback will be executed.
|
|
|
|
* In case or error (SettingNotFoundException) fail callback will be executed.
|
|
|
|
* NOTE: ANDROID only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static watchLocationMode(): Promise<boolean> { return; }
|
2016-05-13 21:58:43 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Stop watching for location mode changes.
|
|
|
|
* NOTE: ANDROID only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static stopWatchingLocationMode() { }
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Method will return all stored locations.
|
|
|
|
* Locations are stored when:
|
|
|
|
* - config.stopOnTerminate is false and main activity was killed
|
|
|
|
* by the system
|
|
|
|
* or
|
|
|
|
* - option.debug is true
|
|
|
|
* NOTE: ANDROID only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getLocations(): Promise<any> { return; }
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-18 05:34:14 +08:00
|
|
|
/**
|
|
|
|
* Delete stored location by given locationId.
|
|
|
|
* NOTE: ANDROID only
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static deleteLocation(locationId: number): Promise<any> { return; }
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-15 10:47:35 +08:00
|
|
|
/**
|
2016-05-18 05:34:14 +08:00
|
|
|
* Delete all stored locations.
|
|
|
|
* NOTE: ANDROID only
|
2016-05-15 10:47:35 +08:00
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-05-18 05:34:14 +08:00
|
|
|
static deleteAllLocations(): Promise<any> { return; }
|
2016-05-15 09:15:51 +08:00
|
|
|
|
2016-05-13 07:26:05 +08:00
|
|
|
}
|