@tauri-apps/plugin-geolocation 2.3.3 → 2.4.1
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/README.md +1 -1
- package/dist-js/index.cjs +78 -0
- package/dist-js/index.d.ts +102 -2
- package/dist-js/index.js +78 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ This plugin provides APIs for getting and tracking the device's current position
|
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
|
-
_This plugin requires a Rust version of at least **1.
|
|
15
|
+
_This plugin requires a Rust version of at least **1.90**_
|
|
16
16
|
|
|
17
17
|
There are three general methods of installation that we can recommend.
|
|
18
18
|
|
package/dist-js/index.cjs
CHANGED
|
@@ -5,6 +5,34 @@ var core = require('@tauri-apps/api/core');
|
|
|
5
5
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
// SPDX-License-Identifier: MIT
|
|
8
|
+
/**
|
|
9
|
+
* Get and track the device's current position, mirroring the W3C Geolocation API.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Registers a callback that is invoked with the device's position whenever it changes, similar to the W3C `navigator.geolocation.watchPosition` API. Pass the returned id to {@link clearWatch} to stop watching.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { watchPosition } from '@tauri-apps/plugin-geolocation';
|
|
19
|
+
* const watchId = await watchPosition(
|
|
20
|
+
* { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
|
|
21
|
+
* (position, error) => {
|
|
22
|
+
* if (error) {
|
|
23
|
+
* console.error(error)
|
|
24
|
+
* } else {
|
|
25
|
+
* console.log(position)
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param options Configuration for the position watcher.
|
|
32
|
+
* @param cb Callback invoked with the new {@link Position} on success, or `null` and an error message when a read fails.
|
|
33
|
+
* @returns A promise resolving to the id of the registered watcher.
|
|
34
|
+
* @since 2.0.0
|
|
35
|
+
*/
|
|
8
36
|
async function watchPosition(options, cb) {
|
|
9
37
|
const channel = new core.Channel();
|
|
10
38
|
channel.onmessage = (message) => {
|
|
@@ -21,19 +49,69 @@ async function watchPosition(options, cb) {
|
|
|
21
49
|
});
|
|
22
50
|
return channel.id;
|
|
23
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns the device's current position, similar to the W3C `navigator.geolocation.getCurrentPosition` API.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { getCurrentPosition } from '@tauri-apps/plugin-geolocation';
|
|
58
|
+
* const position = await getCurrentPosition();
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param options Configuration for the position request.
|
|
62
|
+
* @returns A promise resolving to the current {@link Position}.
|
|
63
|
+
* @since 2.0.0
|
|
64
|
+
*/
|
|
24
65
|
async function getCurrentPosition(options) {
|
|
25
66
|
return await core.invoke('plugin:geolocation|get_current_position', {
|
|
26
67
|
options
|
|
27
68
|
});
|
|
28
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Stops the position watcher registered with {@link watchPosition}.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { clearWatch } from '@tauri-apps/plugin-geolocation';
|
|
76
|
+
* await clearWatch(watchId);
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param channelId The id returned by {@link watchPosition}.
|
|
80
|
+
* @since 2.0.0
|
|
81
|
+
*/
|
|
29
82
|
async function clearWatch(channelId) {
|
|
30
83
|
await core.invoke('plugin:geolocation|clear_watch', {
|
|
31
84
|
channelId
|
|
32
85
|
});
|
|
33
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns the current state of the geolocation permissions. Rejects if location services are disabled on the device.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* import { checkPermissions } from '@tauri-apps/plugin-geolocation';
|
|
93
|
+
* const permission = await checkPermissions();
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @returns A promise resolving to the current {@link PermissionStatus}.
|
|
97
|
+
* @since 2.0.0
|
|
98
|
+
*/
|
|
34
99
|
async function checkPermissions() {
|
|
35
100
|
return await core.checkPermissions('geolocation');
|
|
36
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Requests the given geolocation permissions, prompting the user if needed. Rejects if location services are disabled on the device.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { requestPermissions } from '@tauri-apps/plugin-geolocation';
|
|
108
|
+
* const permission = await requestPermissions(['location']);
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @param permissions The permissions to request, or `null` to request all of them.
|
|
112
|
+
* @returns A promise resolving to the resulting {@link PermissionStatus}.
|
|
113
|
+
* @since 2.0.0
|
|
114
|
+
*/
|
|
37
115
|
async function requestPermissions(permissions) {
|
|
38
116
|
return await core.invoke('plugin:geolocation|request_permissions', {
|
|
39
117
|
permissions
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get and track the device's current position, mirroring the W3C Geolocation API.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { PermissionState } from '@tauri-apps/api/core';
|
|
7
|
+
/**
|
|
8
|
+
* The GPS coordinates of a {@link Position}, along with the accuracy of each reading.
|
|
9
|
+
*/
|
|
2
10
|
export type Coordinates = {
|
|
3
11
|
/**
|
|
4
12
|
* Latitude in decimal degrees.
|
|
@@ -21,12 +29,18 @@ export type Coordinates = {
|
|
|
21
29
|
* The altitude the user is at, if available.
|
|
22
30
|
*/
|
|
23
31
|
altitude: number | null;
|
|
32
|
+
/**
|
|
33
|
+
* The speed the user is traveling, in meters per second, if available.
|
|
34
|
+
*/
|
|
24
35
|
speed: number | null;
|
|
25
36
|
/**
|
|
26
37
|
* The heading the user is facing, if available.
|
|
27
38
|
*/
|
|
28
39
|
heading: number | null;
|
|
29
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The current permission state for the geolocation APIs.
|
|
43
|
+
*/
|
|
30
44
|
export type PermissionStatus = {
|
|
31
45
|
/**
|
|
32
46
|
* Permission state for the location alias.
|
|
@@ -47,17 +61,30 @@ export type PermissionStatus = {
|
|
|
47
61
|
*/
|
|
48
62
|
coarseLocation: PermissionState;
|
|
49
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* The individual permission aliases that can be requested with {@link requestPermissions}.
|
|
66
|
+
*
|
|
67
|
+
* `location` maps to both the coarse and fine location permissions on Android and to the standard
|
|
68
|
+
* location permission on iOS. `coarseLocation` maps to the coarse location permission only on
|
|
69
|
+
* Android, and behaves the same as `location` on iOS.
|
|
70
|
+
*/
|
|
50
71
|
export type PermissionType = 'location' | 'coarseLocation';
|
|
72
|
+
/**
|
|
73
|
+
* A geolocation reading, as returned by {@link getCurrentPosition} and passed to the callback of {@link watchPosition}.
|
|
74
|
+
*/
|
|
51
75
|
export type Position = {
|
|
52
76
|
/**
|
|
53
|
-
* Creation time for these coordinates.
|
|
77
|
+
* Creation time for these coordinates, in milliseconds since the Unix epoch.
|
|
54
78
|
*/
|
|
55
79
|
timestamp: number;
|
|
56
80
|
/**
|
|
57
|
-
* The
|
|
81
|
+
* The GPS coordinates along with the accuracy of the data.
|
|
58
82
|
*/
|
|
59
83
|
coords: Coordinates;
|
|
60
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Options used to configure a {@link getCurrentPosition} or {@link watchPosition} request.
|
|
87
|
+
*/
|
|
61
88
|
export type PositionOptions = {
|
|
62
89
|
/**
|
|
63
90
|
* High accuracy mode (such as GPS, if available)
|
|
@@ -77,8 +104,81 @@ export type PositionOptions = {
|
|
|
77
104
|
*/
|
|
78
105
|
maximumAge: number;
|
|
79
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Registers a callback that is invoked with the device's position whenever it changes, similar to the W3C `navigator.geolocation.watchPosition` API. Pass the returned id to {@link clearWatch} to stop watching.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* import { watchPosition } from '@tauri-apps/plugin-geolocation';
|
|
113
|
+
* const watchId = await watchPosition(
|
|
114
|
+
* { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
|
|
115
|
+
* (position, error) => {
|
|
116
|
+
* if (error) {
|
|
117
|
+
* console.error(error)
|
|
118
|
+
* } else {
|
|
119
|
+
* console.log(position)
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* );
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param options Configuration for the position watcher.
|
|
126
|
+
* @param cb Callback invoked with the new {@link Position} on success, or `null` and an error message when a read fails.
|
|
127
|
+
* @returns A promise resolving to the id of the registered watcher.
|
|
128
|
+
* @since 2.0.0
|
|
129
|
+
*/
|
|
80
130
|
export declare function watchPosition(options: PositionOptions, cb: (location: Position | null, error?: string) => void): Promise<number>;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the device's current position, similar to the W3C `navigator.geolocation.getCurrentPosition` API.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { getCurrentPosition } from '@tauri-apps/plugin-geolocation';
|
|
137
|
+
* const position = await getCurrentPosition();
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @param options Configuration for the position request.
|
|
141
|
+
* @returns A promise resolving to the current {@link Position}.
|
|
142
|
+
* @since 2.0.0
|
|
143
|
+
*/
|
|
81
144
|
export declare function getCurrentPosition(options?: PositionOptions): Promise<Position>;
|
|
145
|
+
/**
|
|
146
|
+
* Stops the position watcher registered with {@link watchPosition}.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { clearWatch } from '@tauri-apps/plugin-geolocation';
|
|
151
|
+
* await clearWatch(watchId);
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @param channelId The id returned by {@link watchPosition}.
|
|
155
|
+
* @since 2.0.0
|
|
156
|
+
*/
|
|
82
157
|
export declare function clearWatch(channelId: number): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the current state of the geolocation permissions. Rejects if location services are disabled on the device.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* import { checkPermissions } from '@tauri-apps/plugin-geolocation';
|
|
164
|
+
* const permission = await checkPermissions();
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @returns A promise resolving to the current {@link PermissionStatus}.
|
|
168
|
+
* @since 2.0.0
|
|
169
|
+
*/
|
|
83
170
|
export declare function checkPermissions(): Promise<PermissionStatus>;
|
|
171
|
+
/**
|
|
172
|
+
* Requests the given geolocation permissions, prompting the user if needed. Rejects if location services are disabled on the device.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* import { requestPermissions } from '@tauri-apps/plugin-geolocation';
|
|
177
|
+
* const permission = await requestPermissions(['location']);
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @param permissions The permissions to request, or `null` to request all of them.
|
|
181
|
+
* @returns A promise resolving to the resulting {@link PermissionStatus}.
|
|
182
|
+
* @since 2.0.0
|
|
183
|
+
*/
|
|
84
184
|
export declare function requestPermissions(permissions: PermissionType[] | null): Promise<PermissionStatus>;
|
package/dist-js/index.js
CHANGED
|
@@ -3,6 +3,34 @@ import { Channel, invoke, checkPermissions as checkPermissions$1 } from '@tauri-
|
|
|
3
3
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
// SPDX-License-Identifier: MIT
|
|
6
|
+
/**
|
|
7
|
+
* Get and track the device's current position, mirroring the W3C Geolocation API.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Registers a callback that is invoked with the device's position whenever it changes, similar to the W3C `navigator.geolocation.watchPosition` API. Pass the returned id to {@link clearWatch} to stop watching.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { watchPosition } from '@tauri-apps/plugin-geolocation';
|
|
17
|
+
* const watchId = await watchPosition(
|
|
18
|
+
* { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
|
|
19
|
+
* (position, error) => {
|
|
20
|
+
* if (error) {
|
|
21
|
+
* console.error(error)
|
|
22
|
+
* } else {
|
|
23
|
+
* console.log(position)
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param options Configuration for the position watcher.
|
|
30
|
+
* @param cb Callback invoked with the new {@link Position} on success, or `null` and an error message when a read fails.
|
|
31
|
+
* @returns A promise resolving to the id of the registered watcher.
|
|
32
|
+
* @since 2.0.0
|
|
33
|
+
*/
|
|
6
34
|
async function watchPosition(options, cb) {
|
|
7
35
|
const channel = new Channel();
|
|
8
36
|
channel.onmessage = (message) => {
|
|
@@ -19,19 +47,69 @@ async function watchPosition(options, cb) {
|
|
|
19
47
|
});
|
|
20
48
|
return channel.id;
|
|
21
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the device's current position, similar to the W3C `navigator.geolocation.getCurrentPosition` API.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { getCurrentPosition } from '@tauri-apps/plugin-geolocation';
|
|
56
|
+
* const position = await getCurrentPosition();
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param options Configuration for the position request.
|
|
60
|
+
* @returns A promise resolving to the current {@link Position}.
|
|
61
|
+
* @since 2.0.0
|
|
62
|
+
*/
|
|
22
63
|
async function getCurrentPosition(options) {
|
|
23
64
|
return await invoke('plugin:geolocation|get_current_position', {
|
|
24
65
|
options
|
|
25
66
|
});
|
|
26
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Stops the position watcher registered with {@link watchPosition}.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { clearWatch } from '@tauri-apps/plugin-geolocation';
|
|
74
|
+
* await clearWatch(watchId);
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param channelId The id returned by {@link watchPosition}.
|
|
78
|
+
* @since 2.0.0
|
|
79
|
+
*/
|
|
27
80
|
async function clearWatch(channelId) {
|
|
28
81
|
await invoke('plugin:geolocation|clear_watch', {
|
|
29
82
|
channelId
|
|
30
83
|
});
|
|
31
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the current state of the geolocation permissions. Rejects if location services are disabled on the device.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { checkPermissions } from '@tauri-apps/plugin-geolocation';
|
|
91
|
+
* const permission = await checkPermissions();
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @returns A promise resolving to the current {@link PermissionStatus}.
|
|
95
|
+
* @since 2.0.0
|
|
96
|
+
*/
|
|
32
97
|
async function checkPermissions() {
|
|
33
98
|
return await checkPermissions$1('geolocation');
|
|
34
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Requests the given geolocation permissions, prompting the user if needed. Rejects if location services are disabled on the device.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { requestPermissions } from '@tauri-apps/plugin-geolocation';
|
|
106
|
+
* const permission = await requestPermissions(['location']);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param permissions The permissions to request, or `null` to request all of them.
|
|
110
|
+
* @returns A promise resolving to the resulting {@link PermissionStatus}.
|
|
111
|
+
* @since 2.0.0
|
|
112
|
+
*/
|
|
35
113
|
async function requestPermissions(permissions) {
|
|
36
114
|
return await invoke('plugin:geolocation|request_permissions', {
|
|
37
115
|
permissions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-geolocation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"license": "MIT OR Apache-2.0",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Tauri Programme within The Commons Conservancy"
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tauri-apps/api": "^2.
|
|
27
|
+
"@tauri-apps/api": "^2.12.0"
|
|
28
28
|
}
|
|
29
29
|
}
|