@tauri-apps/plugin-geolocation
このコンテンツはまだ日本語訳がありません。
Get and track the device’s current position, mirroring the W3C Geolocation API.
Type Aliases
Section titled “Type Aliases”Coordinates
Section titled “Coordinates”type Coordinates = object;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L21
The GPS coordinates of a Position, along with the accuracy of each reading.
Properties
Section titled “Properties”PermissionStatus
Section titled “PermissionStatus”type PermissionStatus = object;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L56
The current permission state for the geolocation APIs.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
coarseLocation |
PermissionState |
Permissions state for the coarseLoaction alias. On Android it requests/checks ACCESS_COARSE_LOCATION. On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) and Precise location (ACCESS_FINE_LOCATION). On iOS it will have the same value as the location alias. |
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L74 |
location |
PermissionState |
Permission state for the location alias. On Android it requests/checks both ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions. On iOS it requests/checks location permissions. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L64 |
PermissionType
Section titled “PermissionType”type PermissionType = "location" | "coarseLocation";Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L84
The individual permission aliases that can be requested with requestPermissions.
location maps to both the coarse and fine location permissions on Android and to the standard
location permission on iOS. coarseLocation maps to the coarse location permission only on
Android, and behaves the same as location on iOS.
Position
Section titled “Position”type Position = object;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L89
A geolocation reading, as returned by getCurrentPosition and passed to the callback of watchPosition.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
coords |
Coordinates |
The GPS coordinates along with the accuracy of the data. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L97 |
timestamp |
number |
Creation time for these coordinates, in milliseconds since the Unix epoch. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L93 |
PositionOptions
Section titled “PositionOptions”type PositionOptions = object;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L103
Options used to configure a getCurrentPosition or watchPosition request.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
enableHighAccuracy |
boolean |
High accuracy mode (such as GPS, if available) Will be ignored on Android 12+ if users didn’t grant the ACCESS_FINE_LOCATION permission (coarseLocation permission). |
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L108 |
maximumAge |
number |
The maximum age in milliseconds of a possible cached position that is acceptable to return. Default: 0 Ignored on iOS | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L120 |
timeout |
number |
The maximum wait time in milliseconds for location updates. On Android the timeout gets ignored for getCurrentPosition. Ignored on iOS | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L114 |
Functions
Section titled “Functions”checkPermissions()
Section titled “checkPermissions()”function checkPermissions(): Promise<PermissionStatus>;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L216
Returns the current state of the geolocation permissions. Rejects if location services are disabled on the device.
Returns
Section titled “Returns”A promise resolving to the current PermissionStatus.
Example
Section titled “Example”import { checkPermissions } from '@tauri-apps/plugin-geolocation';const permission = await checkPermissions();2.0.0
clearWatch()
Section titled “clearWatch()”function clearWatch(channelId): Promise<void>;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L198
Stops the position watcher registered with watchPosition.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
channelId |
number |
The id returned by watchPosition. |
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”import { clearWatch } from '@tauri-apps/plugin-geolocation';await clearWatch(watchId);2.0.0
getCurrentPosition()
Section titled “getCurrentPosition()”function getCurrentPosition(options?): Promise<Position>;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L178
Returns the device’s current position, similar to the W3C navigator.geolocation.getCurrentPosition API.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options? |
PositionOptions |
Configuration for the position request. |
Returns
Section titled “Returns”A promise resolving to the current Position.
Example
Section titled “Example”import { getCurrentPosition } from '@tauri-apps/plugin-geolocation';const position = await getCurrentPosition();2.0.0
requestPermissions()
Section titled “requestPermissions()”function requestPermissions(permissions): Promise<PermissionStatus>;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L233
Requests the given geolocation permissions, prompting the user if needed. Rejects if location services are disabled on the device.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
permissions |
| PermissionType[] | null |
The permissions to request, or null to request all of them. |
Returns
Section titled “Returns”A promise resolving to the resulting PermissionStatus.
Example
Section titled “Example”import { requestPermissions } from '@tauri-apps/plugin-geolocation';const permission = await requestPermissions(['location']);2.0.0
watchPosition()
Section titled “watchPosition()”function watchPosition(options, cb): Promise<number>;Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L146
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 clearWatch to stop watching.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
PositionOptions |
Configuration for the position watcher. |
cb |
(location, error?) => void |
Callback invoked with the new Position on success, or null and an error message when a read fails. |
Returns
Section titled “Returns”Promise<number>
A promise resolving to the id of the registered watcher.
Example
Section titled “Example”import { watchPosition } from '@tauri-apps/plugin-geolocation';const watchId = await watchPosition( { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 }, (position, error) => { if (error) { console.error(error) } else { console.log(position) } });2.0.0
© 2026 Tauri Contributors. CC-BY / MIT