mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-31 18:49:43 +08:00
chore(geolocation): update
This commit is contained in:
parent
0fc8b0f929
commit
1192fd4677
103
dist/plugins/geolocation.d.ts
vendored
103
dist/plugins/geolocation.d.ts
vendored
@ -1,3 +1,80 @@
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
export interface Coordinates {
|
||||
/**
|
||||
* a double representing the position's latitude in decimal degrees.
|
||||
*/
|
||||
latitude: number;
|
||||
/**
|
||||
* A double representing the position's longitude in decimal degrees.
|
||||
*/
|
||||
longitude: number;
|
||||
/**
|
||||
* A double representing the accuracy of the latitude and longitude properties,
|
||||
* expressed in meters.
|
||||
*/
|
||||
accuracy: number;
|
||||
/**
|
||||
* A double representing the position's altitude in metres, relative to sea
|
||||
* level. This value can be null if the implementation cannot provide the data.
|
||||
*/
|
||||
altitude: number;
|
||||
/**
|
||||
* A double representing the accuracy of the altitude expressed in meters.
|
||||
* This value can be null.
|
||||
*/
|
||||
altitudeAccuracy: number;
|
||||
/**
|
||||
* A double representing the direction in which the device is traveling. This
|
||||
* value, specified in degrees, indicates how far off from heading true north
|
||||
* the device is. 0 degrees represents true north, and the direction is
|
||||
* determined clockwise (which means that east is 90 degrees and west is 270
|
||||
* degrees). If speed is 0, heading is NaN. If the device is unable to provide
|
||||
* heading information, this value is null.
|
||||
*/
|
||||
heading: number;
|
||||
/**
|
||||
* A double representing the velocity of the device in meters per second.
|
||||
* This value can be null.
|
||||
*/
|
||||
speed: number;
|
||||
}
|
||||
export interface Geoposition {
|
||||
/**
|
||||
* A Coordinates object defining the current location
|
||||
*/
|
||||
coords: Coordinates;
|
||||
/**
|
||||
* A timestamp representing the time at which the location was retrieved.
|
||||
*/
|
||||
timestamp: number;
|
||||
}
|
||||
export interface GeolocationOptions {
|
||||
/**
|
||||
* Is a positive long value indicating the maximum age in milliseconds of a
|
||||
* possible cached position that is acceptable to return. If set to 0, it
|
||||
* means that the device cannot use a cached position and must attempt to
|
||||
* retrieve the real current position. If set to Infinity the device must
|
||||
* return a cached position regardless of its age. Default: 0.
|
||||
*/
|
||||
maximumAge: number;
|
||||
/**
|
||||
* Is a positive long value representing the maximum length of time
|
||||
* (in milliseconds) the device is allowed to take in order to return a
|
||||
* position. The default value is Infinity, meaning that getCurrentPosition()
|
||||
* won't return until the position is available.
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* Indicates the application would like to receive the best possible results.
|
||||
* If true and if the device is able to provide a more accurate position, it
|
||||
* will do so. Note that this can result in slower response times or increased
|
||||
* power consumption (with a GPS chip on a mobile device for example). On the
|
||||
* other hand, if false, the device can take the liberty to save resources by
|
||||
* responding more quickly and/or using less power. Default: false.
|
||||
* @type {boolean}
|
||||
*/
|
||||
enableHighAccuracy: boolean;
|
||||
}
|
||||
/**
|
||||
* Get geolocation data.
|
||||
*
|
||||
@ -16,6 +93,28 @@
|
||||
* ```
|
||||
*/
|
||||
export declare class Geolocation {
|
||||
static getCurrentPosition(options: any): void;
|
||||
static watchPosition(options: any): void;
|
||||
/**
|
||||
* Get the device's current position.
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return 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.
|
||||
*/
|
||||
static getCurrentPosition(options: GeolocationOptions): Promise<Geoposition>;
|
||||
/**
|
||||
* Watch the current device's position. Clear the watch by unsubscribing from
|
||||
* Observable changes.
|
||||
*
|
||||
* ```
|
||||
* var subscription = Geolocation.watchPosition().subscribe(position => {
|
||||
* console.log(position.coords.longitude + ' ' + position.coords.latitude);
|
||||
* });
|
||||
*
|
||||
* // To stop notifications
|
||||
* subscription.unsubscribe();
|
||||
* ```
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.
|
||||
*/
|
||||
static watchPosition(options: GeolocationOptions): Observable<Geoposition>;
|
||||
}
|
||||
|
42
dist/plugins/geolocation.js
vendored
42
dist/plugins/geolocation.js
vendored
@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var plugin_1 = require('./plugin');
|
||||
var Observable_1 = require('rxjs/Observable');
|
||||
/**
|
||||
* Get geolocation data.
|
||||
*
|
||||
@ -25,9 +26,44 @@ var plugin_1 = require('./plugin');
|
||||
var Geolocation = (function () {
|
||||
function Geolocation() {
|
||||
}
|
||||
Geolocation.getCurrentPosition = function (options) { };
|
||||
;
|
||||
Geolocation.watchPosition = function (options) { };
|
||||
/**
|
||||
* Get the device's current position.
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return 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.
|
||||
*/
|
||||
Geolocation.getCurrentPosition = function (options) {
|
||||
// This Promise is replaced by one from the @Cordova decorator that wraps
|
||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||
// knows that the correct return type is Promise, because there's no way
|
||||
// for it to know the return type from a decorator.
|
||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||
return new Promise(function (res, rej) { });
|
||||
};
|
||||
/**
|
||||
* Watch the current device's position. Clear the watch by unsubscribing from
|
||||
* Observable changes.
|
||||
*
|
||||
* ```
|
||||
* var subscription = Geolocation.watchPosition().subscribe(position => {
|
||||
* console.log(position.coords.longitude + ' ' + position.coords.latitude);
|
||||
* });
|
||||
*
|
||||
* // To stop notifications
|
||||
* subscription.unsubscribe();
|
||||
* ```
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.
|
||||
*/
|
||||
Geolocation.watchPosition = function (options) {
|
||||
// This Observable is replaced by one from the @Cordova decorator that wraps
|
||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||
// knows that the correct return type is Observable, because there's no way
|
||||
// for it to know the return type from a decorator.
|
||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||
return new Observable_1.Observable(function (observer) { });
|
||||
};
|
||||
;
|
||||
__decorate([
|
||||
plugin_1.Cordova()
|
||||
|
2
dist/plugins/geolocation.js.map
vendored
2
dist/plugins/geolocation.js.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../src/plugins/geolocation.ts"],"names":["Geolocation","Geolocation.constructor","Geolocation.getCurrentPosition","Geolocation.watchPosition"],"mappings":";;;;;;AAAA,uBAA8B,UAAU,CAAC,CAAA;AAOzC;;;;;;;;;;;;;;;;GAgBG;AACH;IAAAA;IAgBAC,CAACA;IATQD,8BAAkBA,GADzBA,UAC0BA,OAAWA,IAAEE,CAACA;;IAQjCF,yBAAaA,GALpBA,UAKqBA,OAAWA,IAAEG,CAACA;;IATnCH;QAACA,gBAAOA,EAAEA;OACHA,iCAAkBA,QAAeA;IAGxCA;QAACA,gBAAOA,CAACA;YACPA,aAAaA,EAAEA,SAASA;YACxBA,UAAUA,EAAEA,IAAIA;YAChBA,aAAaA,EAAEA,YAAYA;SAC5BA,CAACA;OACKA,4BAAaA,QAAeA;IAfrCA;QAACA,eAAMA,CAACA;YACNA,IAAIA,EAAEA,aAAaA;YACnBA,MAAMA,EAAEA,4BAA4BA;YACpCA,SAASA,EAAEA,uBAAuBA;SACnCA,CAACA;oBAYDA;IAADA,kBAACA;AAADA,CAACA,AAhBD,IAgBC;AAXY,mBAAW,cAWvB,CAAA"}
|
||||
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../src/plugins/geolocation.ts"],"names":["Geolocation","Geolocation.constructor","Geolocation.getCurrentPosition","Geolocation.watchPosition"],"mappings":";;;;;;AAAA,uBAA8B,UAAU,CAAC,CAAA;AACzC,2BAAyB,iBAAiB,CAAC,CAAA;AA6F3C;;;;;;;;;;;;;;;;GAgBG;AACH;IAAAA;IAmDAC,CAACA;IA7CCD;;;;;OAKGA;IAEIA,8BAAkBA,GADzBA,UAC0BA,OAA2BA;QACnDE,yEAAyEA;QACzEA,oEAAoEA;QACpEA,wEAAwEA;QACxEA,mDAAmDA;QACnDA,0DAA0DA;QAC1DA,MAAMA,CAACA,IAAIA,OAAOA,CAAcA,UAACA,GAAGA,EAAEA,GAAGA,IAAMA,CAACA,CAACA,CAACA;IACpDA,CAACA;IAEDF;;;;;;;;;;;;;;;OAeGA;IAMIA,yBAAaA,GALpBA,UAKqBA,OAA2BA;QAC9CG,4EAA4EA;QAC5EA,oEAAoEA;QACpEA,2EAA2EA;QAC3EA,mDAAmDA;QACnDA,0DAA0DA;QAC1DA,MAAMA,CAACA,IAAIA,uBAAUA,CAAcA,UAAAA,QAAQA,IAAKA,CAACA,CAACA,CAACA;IACrDA,CAACA;;IAtCDH;QAACA,gBAAOA,EAAEA;OACHA,iCAAkBA,QAOxBA;IAkBDA;QAACA,gBAAOA,CAACA;YACPA,aAAaA,EAAEA,SAASA;YACxBA,UAAUA,EAAEA,IAAIA;YAChBA,aAAaA,EAAEA,YAAYA;SAC5BA,CAACA;OACKA,4BAAaA,QAOnBA;IAlDHA;QAACA,eAAMA,CAACA;YACNA,IAAIA,EAAEA,aAAaA;YACnBA,MAAMA,EAAEA,4BAA4BA;YACpCA,SAASA,EAAEA,uBAAuBA;SACnCA,CAACA;oBA+CDA;IAADA,kBAACA;AAADA,CAACA,AAnDD,IAmDC;AA9CY,mBAAW,cA8CvB,CAAA"}
|
@ -1,9 +1,96 @@
|
||||
import {Plugin, Cordova} from './plugin';
|
||||
|
||||
declare var Promise;
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
declare var window;
|
||||
|
||||
export interface Coordinates {
|
||||
/**
|
||||
* a double representing the position's latitude in decimal degrees.
|
||||
*/
|
||||
latitude: number;
|
||||
|
||||
/**
|
||||
* A double representing the position's longitude in decimal degrees.
|
||||
*/
|
||||
longitude: number;
|
||||
|
||||
/**
|
||||
* A double representing the accuracy of the latitude and longitude properties,
|
||||
* expressed in meters.
|
||||
*/
|
||||
accuracy: number;
|
||||
|
||||
/**
|
||||
* A double representing the position's altitude in metres, relative to sea
|
||||
* level. This value can be null if the implementation cannot provide the data.
|
||||
*/
|
||||
altitude: number;
|
||||
|
||||
/**
|
||||
* A double representing the accuracy of the altitude expressed in meters.
|
||||
* This value can be null.
|
||||
*/
|
||||
altitudeAccuracy: number;
|
||||
|
||||
/**
|
||||
* A double representing the direction in which the device is traveling. This
|
||||
* value, specified in degrees, indicates how far off from heading true north
|
||||
* the device is. 0 degrees represents true north, and the direction is
|
||||
* determined clockwise (which means that east is 90 degrees and west is 270
|
||||
* degrees). If speed is 0, heading is NaN. If the device is unable to provide
|
||||
* heading information, this value is null.
|
||||
*/
|
||||
heading: number;
|
||||
|
||||
/**
|
||||
* A double representing the velocity of the device in meters per second.
|
||||
* This value can be null.
|
||||
*/
|
||||
speed: number;
|
||||
}
|
||||
|
||||
export interface Geoposition {
|
||||
/**
|
||||
* A Coordinates object defining the current location
|
||||
*/
|
||||
coords: Coordinates;
|
||||
|
||||
/**
|
||||
* A timestamp representing the time at which the location was retrieved.
|
||||
*/
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface GeolocationOptions {
|
||||
/**
|
||||
* Is a positive long value indicating the maximum age in milliseconds of a
|
||||
* possible cached position that is acceptable to return. If set to 0, it
|
||||
* means that the device cannot use a cached position and must attempt to
|
||||
* retrieve the real current position. If set to Infinity the device must
|
||||
* return a cached position regardless of its age. Default: 0.
|
||||
*/
|
||||
maximumAge: number;
|
||||
|
||||
/**
|
||||
* Is a positive long value representing the maximum length of time
|
||||
* (in milliseconds) the device is allowed to take in order to return a
|
||||
* position. The default value is Infinity, meaning that getCurrentPosition()
|
||||
* won't return until the position is available.
|
||||
*/
|
||||
timeout: number;
|
||||
|
||||
/**
|
||||
* Indicates the application would like to receive the best possible results.
|
||||
* If true and if the device is able to provide a more accurate position, it
|
||||
* will do so. Note that this can result in slower response times or increased
|
||||
* power consumption (with a GPS chip on a mobile device for example). On the
|
||||
* other hand, if false, the device can take the liberty to save resources by
|
||||
* responding more quickly and/or using less power. Default: false.
|
||||
* @type {boolean}
|
||||
*/
|
||||
enableHighAccuracy: boolean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get geolocation data.
|
||||
@ -28,14 +115,49 @@ declare var window;
|
||||
pluginRef: 'navigator.geolocation'
|
||||
})
|
||||
export class Geolocation {
|
||||
/**
|
||||
* Get the device's current position.
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return 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.
|
||||
*/
|
||||
@Cordova()
|
||||
static getCurrentPosition(options:any){};
|
||||
|
||||
static getCurrentPosition(options: GeolocationOptions){
|
||||
// This Promise is replaced by one from the @Cordova decorator that wraps
|
||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||
// knows that the correct return type is Promise, because there's no way
|
||||
// for it to know the return type from a decorator.
|
||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||
return new Promise<Geoposition>((res, rej) => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch the current device's position. Clear the watch by unsubscribing from
|
||||
* Observable changes.
|
||||
*
|
||||
* ```
|
||||
* var subscription = Geolocation.watchPosition().subscribe(position => {
|
||||
* console.log(position.coords.longitude + ' ' + position.coords.latitude);
|
||||
* });
|
||||
*
|
||||
* // To stop notifications
|
||||
* subscription.unsubscribe();
|
||||
* ```
|
||||
*
|
||||
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
|
||||
* @return Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.
|
||||
*/
|
||||
@Cordova({
|
||||
callbackOrder: 'reverse',
|
||||
observable: true,
|
||||
clearFunction: 'clearWatch'
|
||||
})
|
||||
static watchPosition(options:any){};
|
||||
static watchPosition(options: GeolocationOptions){
|
||||
// This Observable is replaced by one from the @Cordova decorator that wraps
|
||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||
// knows that the correct return type is Observable, because there's no way
|
||||
// for it to know the return type from a decorator.
|
||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||
return new Observable<Geoposition>(observer => {});
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user