@nitra/geolocation 7.1.5 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NitraGeolocation.podspec +18 -0
- package/Package.swift +6 -10
- package/README.md +102 -11
- package/android/build.gradle +51 -22
- package/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationErrors.kt +10 -0
- package/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt +236 -32
- package/dist/docs.json +37 -5
- package/dist/esm/definitions.d.ts +87 -7
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +62 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +66 -9
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +66 -9
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/GeolocationPlugin/GeolocationCallbackManager.swift +9 -0
- package/ios/Sources/GeolocationPlugin/GeolocationConstants.swift +5 -0
- package/ios/Sources/GeolocationPlugin/GeolocationError.swift +4 -1
- package/ios/Sources/GeolocationPlugin/GeolocationPlugin.swift +66 -19
- package/ios/Sources/GeolocationPlugin/IONGLOCPositionModel+JSONTransformer.swift +8 -3
- package/package.json +24 -22
package/dist/esm/web.js
CHANGED
|
@@ -1,9 +1,69 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
2
|
export class GeolocationWeb extends WebPlugin {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.latestOrientation = null;
|
|
6
|
+
if (typeof window !== 'undefined') {
|
|
7
|
+
const win = window;
|
|
8
|
+
if ('ondeviceorientationabsolute' in win) {
|
|
9
|
+
win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
|
|
10
|
+
}
|
|
11
|
+
else if ('ondeviceorientation' in win) {
|
|
12
|
+
win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
updateOrientation(event, isAbsolute) {
|
|
17
|
+
let trueHeading = null;
|
|
18
|
+
let magneticHeading = null;
|
|
19
|
+
let headingAccuracy = null;
|
|
20
|
+
if (isAbsolute && event.alpha !== null) {
|
|
21
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
22
|
+
}
|
|
23
|
+
else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
|
|
24
|
+
magneticHeading = event.webkitCompassHeading;
|
|
25
|
+
headingAccuracy = event.webkitCompassAccuracy;
|
|
26
|
+
}
|
|
27
|
+
else if (event.alpha !== null && event.absolute === true) {
|
|
28
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
29
|
+
}
|
|
30
|
+
else if (event.alpha !== null) {
|
|
31
|
+
magneticHeading = (360 - event.alpha) % 360;
|
|
32
|
+
}
|
|
33
|
+
if (trueHeading !== null || magneticHeading !== null) {
|
|
34
|
+
this.latestOrientation = {
|
|
35
|
+
trueHeading,
|
|
36
|
+
magneticHeading,
|
|
37
|
+
headingAccuracy,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
augmentPosition(pos, isWatch = false) {
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
43
|
+
const coords = pos.coords;
|
|
44
|
+
const orientation = isWatch ? this.latestOrientation : null;
|
|
45
|
+
const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
|
|
46
|
+
return {
|
|
47
|
+
timestamp: null,
|
|
48
|
+
coords: {
|
|
49
|
+
latitude: coords.latitude,
|
|
50
|
+
longitude: coords.longitude,
|
|
51
|
+
accuracy: coords.accuracy,
|
|
52
|
+
altitude: coords.altitude,
|
|
53
|
+
altitudeAccuracy: coords.altitudeAccuracy,
|
|
54
|
+
speed: coords.speed,
|
|
55
|
+
heading: heading,
|
|
56
|
+
magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
|
|
57
|
+
trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
|
|
58
|
+
headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
|
|
59
|
+
course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
3
63
|
async getCurrentPosition(options) {
|
|
4
64
|
return new Promise((resolve, reject) => {
|
|
5
65
|
navigator.geolocation.getCurrentPosition((pos) => {
|
|
6
|
-
resolve(pos);
|
|
66
|
+
resolve(this.augmentPosition(pos, false));
|
|
7
67
|
}, (err) => {
|
|
8
68
|
reject(err);
|
|
9
69
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
|
|
@@ -11,7 +71,7 @@ export class GeolocationWeb extends WebPlugin {
|
|
|
11
71
|
}
|
|
12
72
|
async watchPosition(options, callback) {
|
|
13
73
|
const id = navigator.geolocation.watchPosition((pos) => {
|
|
14
|
-
callback(pos);
|
|
74
|
+
callback(this.augmentPosition(pos, true));
|
|
15
75
|
}, (err) => {
|
|
16
76
|
callback(null, err);
|
|
17
77
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,cAAe,S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B,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,EACb,qBAAqB,EAAE,IAAI,IACxB,OAAO,EAEb,CAAC;QAEF,OAAO,GAAG,EAAE,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAuB;QACtC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;YAC/D,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YACnD,IAAI,EAAE,aAAa;SACpB,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CallbackID,\n GeolocationPlugin,\n PermissionStatus,\n Position,\n PositionOptions,\n WatchPositionCallback,\n} from './definitions';\n\nexport class GeolocationWeb extends WebPlugin implements GeolocationPlugin {\n private latestOrientation: {\n magneticHeading: number | null;\n trueHeading: number | null;\n headingAccuracy: number | null;\n } | null = null;\n\n constructor() {\n super();\n if (typeof window !== 'undefined') {\n const win = window as any;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event: any) => this.updateOrientation(event, true), true);\n } else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event: any) => this.updateOrientation(event, false), true);\n }\n }\n }\n\n private updateOrientation(event: any, isAbsolute: boolean) {\n let trueHeading: number | null = null;\n let magneticHeading: number | null = null;\n let headingAccuracy: number | null = null;\n\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n } else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n } else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n } else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n\n private augmentPosition(pos: globalThis.GeolocationPosition, isWatch = false): Position {\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n\n const heading =\n orientation?.trueHeading ?? orientation?.magneticHeading ?? (isWatch ? coords.heading : null) ?? null;\n\n return {\n timestamp: null,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: (coords as any).altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: orientation?.magneticHeading ?? null,\n trueHeading: orientation?.trueHeading ?? null,\n headingAccuracy: orientation?.headingAccuracy ?? null,\n course: (isWatch ? coords.heading : null) ?? null,\n },\n };\n }\n\n async getCurrentPosition(options?: PositionOptions): Promise<Position> {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n (pos) => {\n resolve(this.augmentPosition(pos, false));\n },\n (err) => {\n reject(err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n ...options,\n },\n );\n });\n }\n\n async watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID> {\n const id = navigator.geolocation.watchPosition(\n (pos) => {\n callback(this.augmentPosition(pos, true));\n },\n (err) => {\n callback(null, err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n minimumUpdateInterval: 5000,\n ...options,\n },\n );\n\n return `${id}`;\n }\n\n async clearWatch(options: { id: string }): Promise<void> {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n\nconst Geolocation = new GeolocationWeb();\n\nexport { Geolocation };\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,20 +1,78 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@capacitor/core');
|
|
6
4
|
var synapse = require('@capacitor/synapse');
|
|
7
5
|
|
|
8
|
-
const Geolocation
|
|
6
|
+
const Geolocation = core.registerPlugin('Geolocation', {
|
|
9
7
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.GeolocationWeb()),
|
|
10
8
|
});
|
|
11
9
|
synapse.exposeSynapse();
|
|
12
10
|
|
|
13
11
|
class GeolocationWeb extends core.WebPlugin {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.latestOrientation = null;
|
|
15
|
+
if (typeof window !== 'undefined') {
|
|
16
|
+
const win = window;
|
|
17
|
+
if ('ondeviceorientationabsolute' in win) {
|
|
18
|
+
win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
|
|
19
|
+
}
|
|
20
|
+
else if ('ondeviceorientation' in win) {
|
|
21
|
+
win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
updateOrientation(event, isAbsolute) {
|
|
26
|
+
let trueHeading = null;
|
|
27
|
+
let magneticHeading = null;
|
|
28
|
+
let headingAccuracy = null;
|
|
29
|
+
if (isAbsolute && event.alpha !== null) {
|
|
30
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
31
|
+
}
|
|
32
|
+
else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
|
|
33
|
+
magneticHeading = event.webkitCompassHeading;
|
|
34
|
+
headingAccuracy = event.webkitCompassAccuracy;
|
|
35
|
+
}
|
|
36
|
+
else if (event.alpha !== null && event.absolute === true) {
|
|
37
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
38
|
+
}
|
|
39
|
+
else if (event.alpha !== null) {
|
|
40
|
+
magneticHeading = (360 - event.alpha) % 360;
|
|
41
|
+
}
|
|
42
|
+
if (trueHeading !== null || magneticHeading !== null) {
|
|
43
|
+
this.latestOrientation = {
|
|
44
|
+
trueHeading,
|
|
45
|
+
magneticHeading,
|
|
46
|
+
headingAccuracy,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
augmentPosition(pos, isWatch = false) {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
52
|
+
const coords = pos.coords;
|
|
53
|
+
const orientation = isWatch ? this.latestOrientation : null;
|
|
54
|
+
const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
|
|
55
|
+
return {
|
|
56
|
+
timestamp: null,
|
|
57
|
+
coords: {
|
|
58
|
+
latitude: coords.latitude,
|
|
59
|
+
longitude: coords.longitude,
|
|
60
|
+
accuracy: coords.accuracy,
|
|
61
|
+
altitude: coords.altitude,
|
|
62
|
+
altitudeAccuracy: coords.altitudeAccuracy,
|
|
63
|
+
speed: coords.speed,
|
|
64
|
+
heading: heading,
|
|
65
|
+
magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
|
|
66
|
+
trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
|
|
67
|
+
headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
|
|
68
|
+
course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
14
72
|
async getCurrentPosition(options) {
|
|
15
73
|
return new Promise((resolve, reject) => {
|
|
16
74
|
navigator.geolocation.getCurrentPosition((pos) => {
|
|
17
|
-
resolve(pos);
|
|
75
|
+
resolve(this.augmentPosition(pos, false));
|
|
18
76
|
}, (err) => {
|
|
19
77
|
reject(err);
|
|
20
78
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
|
|
@@ -22,7 +80,7 @@ class GeolocationWeb extends core.WebPlugin {
|
|
|
22
80
|
}
|
|
23
81
|
async watchPosition(options, callback) {
|
|
24
82
|
const id = navigator.geolocation.watchPosition((pos) => {
|
|
25
|
-
callback(pos);
|
|
83
|
+
callback(this.augmentPosition(pos, true));
|
|
26
84
|
}, (err) => {
|
|
27
85
|
callback(null, err);
|
|
28
86
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
|
|
@@ -44,13 +102,12 @@ class GeolocationWeb extends core.WebPlugin {
|
|
|
44
102
|
throw this.unimplemented('Not implemented on web.');
|
|
45
103
|
}
|
|
46
104
|
}
|
|
47
|
-
|
|
105
|
+
new GeolocationWeb();
|
|
48
106
|
|
|
49
107
|
var web = /*#__PURE__*/Object.freeze({
|
|
50
108
|
__proto__: null,
|
|
51
|
-
GeolocationWeb: GeolocationWeb
|
|
52
|
-
Geolocation: Geolocation
|
|
109
|
+
GeolocationWeb: GeolocationWeb
|
|
53
110
|
});
|
|
54
111
|
|
|
55
|
-
exports.Geolocation = Geolocation
|
|
112
|
+
exports.Geolocation = Geolocation;
|
|
56
113
|
//# sourceMappingURL=plugin.cjs.js.map
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(pos);\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(pos);\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n constructor() {\n super();\n this.latestOrientation = null;\n if (typeof window !== 'undefined') {\n const win = window;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);\n }\n else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);\n }\n }\n }\n updateOrientation(event, isAbsolute) {\n let trueHeading = null;\n let magneticHeading = null;\n let headingAccuracy = null;\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n }\n else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n augmentPosition(pos, isWatch = false) {\n var _a, _b, _c, _d, _e, _f, _g;\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;\n return {\n timestamp: null,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: coords.altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,\n trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,\n headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,\n course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,\n },\n };\n }\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(this.augmentPosition(pos, false));\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(this.augmentPosition(pos, true));\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","exposeSynapse","WebPlugin"],"mappings":";;;;;AAEK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EA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AM,gBAAgB,GAAG;AAC7B,QAAQ,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACxE,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;AACnF,QAAQ;AACR,QAAQ,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;AAC7D,YAAY,IAAI,EAAE,aAAa;AAC/B,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE;AAC/E,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;AACoB,IAAI,cAAc;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,16 +1,76 @@
|
|
|
1
1
|
var capacitorGeolocationPluginCapacitor = (function (exports, core, synapse) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const Geolocation
|
|
4
|
+
const Geolocation = core.registerPlugin('Geolocation', {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.GeolocationWeb()),
|
|
6
6
|
});
|
|
7
7
|
synapse.exposeSynapse();
|
|
8
8
|
|
|
9
9
|
class GeolocationWeb extends core.WebPlugin {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.latestOrientation = null;
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
const win = window;
|
|
15
|
+
if ('ondeviceorientationabsolute' in win) {
|
|
16
|
+
win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
|
|
17
|
+
}
|
|
18
|
+
else if ('ondeviceorientation' in win) {
|
|
19
|
+
win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
updateOrientation(event, isAbsolute) {
|
|
24
|
+
let trueHeading = null;
|
|
25
|
+
let magneticHeading = null;
|
|
26
|
+
let headingAccuracy = null;
|
|
27
|
+
if (isAbsolute && event.alpha !== null) {
|
|
28
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
29
|
+
}
|
|
30
|
+
else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
|
|
31
|
+
magneticHeading = event.webkitCompassHeading;
|
|
32
|
+
headingAccuracy = event.webkitCompassAccuracy;
|
|
33
|
+
}
|
|
34
|
+
else if (event.alpha !== null && event.absolute === true) {
|
|
35
|
+
trueHeading = (360 - event.alpha) % 360;
|
|
36
|
+
}
|
|
37
|
+
else if (event.alpha !== null) {
|
|
38
|
+
magneticHeading = (360 - event.alpha) % 360;
|
|
39
|
+
}
|
|
40
|
+
if (trueHeading !== null || magneticHeading !== null) {
|
|
41
|
+
this.latestOrientation = {
|
|
42
|
+
trueHeading,
|
|
43
|
+
magneticHeading,
|
|
44
|
+
headingAccuracy,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
augmentPosition(pos, isWatch = false) {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
50
|
+
const coords = pos.coords;
|
|
51
|
+
const orientation = isWatch ? this.latestOrientation : null;
|
|
52
|
+
const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
|
|
53
|
+
return {
|
|
54
|
+
timestamp: null,
|
|
55
|
+
coords: {
|
|
56
|
+
latitude: coords.latitude,
|
|
57
|
+
longitude: coords.longitude,
|
|
58
|
+
accuracy: coords.accuracy,
|
|
59
|
+
altitude: coords.altitude,
|
|
60
|
+
altitudeAccuracy: coords.altitudeAccuracy,
|
|
61
|
+
speed: coords.speed,
|
|
62
|
+
heading: heading,
|
|
63
|
+
magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
|
|
64
|
+
trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
|
|
65
|
+
headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
|
|
66
|
+
course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
10
70
|
async getCurrentPosition(options) {
|
|
11
71
|
return new Promise((resolve, reject) => {
|
|
12
72
|
navigator.geolocation.getCurrentPosition((pos) => {
|
|
13
|
-
resolve(pos);
|
|
73
|
+
resolve(this.augmentPosition(pos, false));
|
|
14
74
|
}, (err) => {
|
|
15
75
|
reject(err);
|
|
16
76
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
|
|
@@ -18,7 +78,7 @@ var capacitorGeolocationPluginCapacitor = (function (exports, core, synapse) {
|
|
|
18
78
|
}
|
|
19
79
|
async watchPosition(options, callback) {
|
|
20
80
|
const id = navigator.geolocation.watchPosition((pos) => {
|
|
21
|
-
callback(pos);
|
|
81
|
+
callback(this.augmentPosition(pos, true));
|
|
22
82
|
}, (err) => {
|
|
23
83
|
callback(null, err);
|
|
24
84
|
}, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
|
|
@@ -40,17 +100,14 @@ var capacitorGeolocationPluginCapacitor = (function (exports, core, synapse) {
|
|
|
40
100
|
throw this.unimplemented('Not implemented on web.');
|
|
41
101
|
}
|
|
42
102
|
}
|
|
43
|
-
|
|
103
|
+
new GeolocationWeb();
|
|
44
104
|
|
|
45
105
|
var web = /*#__PURE__*/Object.freeze({
|
|
46
106
|
__proto__: null,
|
|
47
|
-
GeolocationWeb: GeolocationWeb
|
|
48
|
-
Geolocation: Geolocation
|
|
107
|
+
GeolocationWeb: GeolocationWeb
|
|
49
108
|
});
|
|
50
109
|
|
|
51
|
-
exports.Geolocation = Geolocation
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
110
|
+
exports.Geolocation = Geolocation;
|
|
54
111
|
|
|
55
112
|
return exports;
|
|
56
113
|
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(pos);\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(pos);\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n constructor() {\n super();\n this.latestOrientation = null;\n if (typeof window !== 'undefined') {\n const win = window;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);\n }\n else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);\n }\n }\n }\n updateOrientation(event, isAbsolute) {\n let trueHeading = null;\n let magneticHeading = null;\n let headingAccuracy = null;\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n }\n else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n augmentPosition(pos, isWatch = false) {\n var _a, _b, _c, _d, _e, _f, _g;\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;\n return {\n timestamp: null,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: coords.altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,\n trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,\n headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,\n course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,\n },\n };\n }\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(this.augmentPosition(pos, false));\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(this.augmentPosition(pos, true));\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","exposeSynapse","WebPlugin"],"mappings":";;;AAEK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,C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IAC7B,QAAQ,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACxE,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;IACnF,QAAQ;IACR,QAAQ,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;IAC7D,YAAY,IAAI,EAAE,aAAa;IAC/B,SAAS,CAAC;IACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE;IAC/E,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;IACoB,IAAI,cAAc;;;;;;;;;;;;;;;"}
|
|
@@ -24,6 +24,7 @@ final class GeolocationCallbackManager {
|
|
|
24
24
|
private(set) var requestPermissionsCallbacks: [CAPPluginCall]
|
|
25
25
|
private(set) var locationCallbacks: [CAPPluginCall]
|
|
26
26
|
private(set) var watchCallbacks: [String: CAPPluginCall]
|
|
27
|
+
private(set) var timeout: Int?
|
|
27
28
|
private let capacitorBridge: CAPBridgeProtocol?
|
|
28
29
|
|
|
29
30
|
private var allCallbackGroups: [GeolocationCallbackGroup] {
|
|
@@ -52,11 +53,15 @@ final class GeolocationCallbackManager {
|
|
|
52
53
|
func addLocationCallback(capacitorCall call: CAPPluginCall) {
|
|
53
54
|
capacitorBridge?.saveCall(call)
|
|
54
55
|
locationCallbacks.append(call)
|
|
56
|
+
let timeout = call.getInt(Constants.Arguments.timeout)
|
|
57
|
+
self.timeout = timeout
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
func addWatchCallback(_ watchId: String, capacitorCall call: CAPPluginCall) {
|
|
58
61
|
capacitorBridge?.saveCall(call)
|
|
59
62
|
watchCallbacks[watchId] = call
|
|
63
|
+
let timeout = call.getInt(Constants.Arguments.timeout)
|
|
64
|
+
self.timeout = timeout
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
func clearRequestPermissionsCallbacks() {
|
|
@@ -109,6 +114,10 @@ final class GeolocationCallbackManager {
|
|
|
109
114
|
|
|
110
115
|
func sendError(_ error: GeolocationError) {
|
|
111
116
|
createPluginResult(status: .error(error.toCodeMessagePair()))
|
|
117
|
+
|
|
118
|
+
if case .timeout = error {
|
|
119
|
+
watchCallbacks.keys.forEach { clearWatchCallbackIfExists($0) }
|
|
120
|
+
}
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
|
|
@@ -2,6 +2,7 @@ enum Constants {
|
|
|
2
2
|
enum Arguments {
|
|
3
3
|
static let enableHighAccuracy = "enableHighAccuracy"
|
|
4
4
|
static let id = "id"
|
|
5
|
+
static let timeout = "timeout"
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
enum AuthorisationStatus {
|
|
@@ -32,5 +33,9 @@ enum Constants {
|
|
|
32
33
|
static let speed: String = "speed"
|
|
33
34
|
static let timestamp: String = "timestamp"
|
|
34
35
|
static let altitudeAccuracy: String = "altitudeAccuracy"
|
|
36
|
+
static let magneticHeading: String = "magneticHeading"
|
|
37
|
+
static let trueHeading: String = "trueHeading"
|
|
38
|
+
static let headingAccuracy: String = "headingAccuracy"
|
|
39
|
+
static let course: String = "course"
|
|
35
40
|
}
|
|
36
41
|
}
|
|
@@ -10,6 +10,7 @@ enum GeolocationError: Error {
|
|
|
10
10
|
case permissionRestricted
|
|
11
11
|
case positionUnavailable
|
|
12
12
|
case inputArgumentsIssue(target: GeolocationMethod)
|
|
13
|
+
case timeout
|
|
13
14
|
|
|
14
15
|
func toCodeMessagePair() -> (String, String) {
|
|
15
16
|
("OS-PLUG-GLOC-\(String(format: "%04d", code))", description)
|
|
@@ -29,16 +30,18 @@ private extension GeolocationError {
|
|
|
29
30
|
case .watchPosition: 5
|
|
30
31
|
case .clearWatch: 6
|
|
31
32
|
}
|
|
33
|
+
case .timeout: 10
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
var description: String {
|
|
36
38
|
switch self {
|
|
37
|
-
case .positionUnavailable: "There was
|
|
39
|
+
case .positionUnavailable: "There was an error trying to obtain the location."
|
|
38
40
|
case .permissionDenied: "Location permission request was denied."
|
|
39
41
|
case .locationServicesDisabled: "Location services are not enabled."
|
|
40
42
|
case .permissionRestricted: "Application's use of location services was restricted."
|
|
41
43
|
case .inputArgumentsIssue(let target): "The '\(target.rawValue)' input parameters aren't valid."
|
|
44
|
+
case .timeout: "Could not obtain location in time. Try with a higher timeout."
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Capacitor
|
|
2
2
|
import IONGeolocationLib
|
|
3
|
-
|
|
3
|
+
import UIKit
|
|
4
4
|
import Combine
|
|
5
5
|
|
|
6
6
|
@objc(GeolocationPlugin)
|
|
@@ -17,12 +17,41 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
17
17
|
|
|
18
18
|
private var locationService: (any IONGLOCService)?
|
|
19
19
|
private var cancellables = Set<AnyCancellable>()
|
|
20
|
+
private var locationCancellable: AnyCancellable?
|
|
21
|
+
private var timeoutCancellable: AnyCancellable?
|
|
20
22
|
private var callbackManager: GeolocationCallbackManager?
|
|
21
|
-
private var
|
|
23
|
+
private var statusInitialized = false
|
|
24
|
+
private var locationInitialized: Bool = false
|
|
22
25
|
|
|
23
26
|
override public func load() {
|
|
24
27
|
self.locationService = IONGLOCManagerWrapper()
|
|
25
28
|
self.callbackManager = .init(capacitorBridge: bridge)
|
|
29
|
+
|
|
30
|
+
NotificationCenter.default.addObserver(
|
|
31
|
+
self,
|
|
32
|
+
selector: #selector(appDidBecomeActive),
|
|
33
|
+
name: UIApplication.didBecomeActiveNotification,
|
|
34
|
+
object: nil
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objc private func appDidBecomeActive() {
|
|
39
|
+
if let watchCallbacksEmpty = callbackManager?.watchCallbacks.isEmpty, !watchCallbacksEmpty {
|
|
40
|
+
print("App became active. Restarting location monitoring for watch callbacks.")
|
|
41
|
+
locationCancellable?.cancel()
|
|
42
|
+
locationCancellable = nil
|
|
43
|
+
timeoutCancellable?.cancel()
|
|
44
|
+
timeoutCancellable = nil
|
|
45
|
+
locationInitialized = false
|
|
46
|
+
|
|
47
|
+
locationService?.stopMonitoringLocation()
|
|
48
|
+
locationService?.startMonitoringLocation(options: IONGLOCRequestOptionsModel(timeout: callbackManager?.timeout))
|
|
49
|
+
bindLocationPublisher()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
deinit {
|
|
54
|
+
NotificationCenter.default.removeObserver(self)
|
|
26
55
|
}
|
|
27
56
|
|
|
28
57
|
@objc func getCurrentPosition(_ call: CAPPluginCall) {
|
|
@@ -48,6 +77,11 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
48
77
|
|
|
49
78
|
if (callbackManager?.watchCallbacks.isEmpty) ?? false {
|
|
50
79
|
locationService?.stopMonitoringLocation()
|
|
80
|
+
locationCancellable?.cancel()
|
|
81
|
+
locationCancellable = nil
|
|
82
|
+
timeoutCancellable?.cancel()
|
|
83
|
+
timeoutCancellable = nil
|
|
84
|
+
locationInitialized = false
|
|
51
85
|
}
|
|
52
86
|
|
|
53
87
|
callbackManager?.sendSuccess(call)
|
|
@@ -83,12 +117,13 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
83
117
|
|
|
84
118
|
private extension GeolocationPlugin {
|
|
85
119
|
func shouldSetupBindings() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
setupBindings()
|
|
120
|
+
bindAuthorisationStatusPublisher()
|
|
121
|
+
bindLocationPublisher()
|
|
89
122
|
}
|
|
90
123
|
|
|
91
|
-
func
|
|
124
|
+
func bindAuthorisationStatusPublisher() {
|
|
125
|
+
guard !statusInitialized else { return }
|
|
126
|
+
statusInitialized = true
|
|
92
127
|
locationService?.authorisationStatusPublisher
|
|
93
128
|
.sink(receiveValue: { [weak self] status in
|
|
94
129
|
guard let self else { return }
|
|
@@ -106,17 +141,28 @@ private extension GeolocationPlugin {
|
|
|
106
141
|
}
|
|
107
142
|
})
|
|
108
143
|
.store(in: &cancellables)
|
|
144
|
+
}
|
|
109
145
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
146
|
+
func bindLocationPublisher() {
|
|
147
|
+
guard !locationInitialized else { return }
|
|
148
|
+
locationInitialized = true
|
|
149
|
+
locationCancellable = locationService?.currentLocationPublisher
|
|
150
|
+
.catch { [weak self] error -> AnyPublisher<IONGLOCPositionModel, Never> in
|
|
151
|
+
print("An error was found while retrieving the location: \(error)")
|
|
152
|
+
self?.callbackManager?.sendError(.positionUnavailable)
|
|
153
|
+
return Empty<IONGLOCPositionModel, Never>().eraseToAnyPublisher()
|
|
154
|
+
}
|
|
155
|
+
.sink(receiveValue: { [weak self] position in
|
|
156
|
+
self?.callbackManager?.sendSuccess(with: position)
|
|
157
|
+
})
|
|
158
|
+
timeoutCancellable = locationService?.locationTimeoutPublisher
|
|
159
|
+
.sink(receiveValue: { [weak self] error in
|
|
160
|
+
if case .timeout = error {
|
|
161
|
+
self?.callbackManager?.sendError(.timeout)
|
|
162
|
+
} else {
|
|
114
163
|
self?.callbackManager?.sendError(.positionUnavailable)
|
|
115
164
|
}
|
|
116
|
-
}, receiveValue: { [weak self] position in
|
|
117
|
-
self?.callbackManager?.sendSuccess(with: position)
|
|
118
165
|
})
|
|
119
|
-
.store(in: &cancellables)
|
|
120
166
|
}
|
|
121
167
|
|
|
122
168
|
func requestLocationAuthorisation(type requestType: IONGLOCAuthorisationRequestType) {
|
|
@@ -128,10 +174,10 @@ private extension GeolocationPlugin {
|
|
|
128
174
|
|
|
129
175
|
func checkIfLocationServicesAreEnabled(_ call: CAPPluginCall? = nil) -> Bool {
|
|
130
176
|
guard locationService?.areLocationServicesEnabled() == true else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
177
|
+
call.map { callbackManager?.sendError($0, error: .locationServicesDisabled) }
|
|
178
|
+
?? callbackManager?.sendError(.locationServicesDisabled)
|
|
179
|
+
return false
|
|
180
|
+
}
|
|
135
181
|
return true
|
|
136
182
|
}
|
|
137
183
|
|
|
@@ -157,14 +203,15 @@ private extension GeolocationPlugin {
|
|
|
157
203
|
callbackManager?.sendRequestPermissionsSuccess(Constants.AuthorisationStatus.Status.granted)
|
|
158
204
|
}
|
|
159
205
|
if shouldRequestCurrentPosition {
|
|
160
|
-
locationService?.requestSingleLocation()
|
|
206
|
+
locationService?.requestSingleLocation(options: IONGLOCRequestOptionsModel(timeout: callbackManager?.timeout))
|
|
161
207
|
}
|
|
162
208
|
if shouldRequestLocationMonitoring {
|
|
163
|
-
locationService?.startMonitoringLocation()
|
|
209
|
+
locationService?.startMonitoringLocation(options: IONGLOCRequestOptionsModel(timeout: callbackManager?.timeout))
|
|
164
210
|
}
|
|
165
211
|
}
|
|
166
212
|
|
|
167
213
|
func handleLocationRequest(_ enableHighAccuracy: Bool, watchUUID: String? = nil, call: CAPPluginCall) {
|
|
214
|
+
bindLocationPublisher()
|
|
168
215
|
let configurationModel = IONGLOCConfigurationModel(enableHighAccuracy: enableHighAccuracy)
|
|
169
216
|
locationService?.updateConfiguration(configurationModel)
|
|
170
217
|
|