コンテンツにスキップ

@tauri-apps/plugin-geolocation

このコンテンツはまだ日本語訳がありません。

Get and track the device’s current position, mirroring the W3C Geolocation API.

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.

Property Type Description Defined in
accuracy number Accuracy level of the latitude and longitude coordinates in meters. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L33
altitude number | null The altitude the user is at, if available. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L42
altitudeAccuracy number | null Accuracy level of the altitude coordinate in meters, if available. Available on all iOS versions and on Android 8 and above. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L38
heading number | null The heading the user is facing, if available. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L50
latitude number Latitude in decimal degrees. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L25
longitude number Longitude in decimal degrees. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L29
speed number | null The speed the user is traveling, in meters per second, if available. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/geolocation/guest-js/index.ts#L46

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.

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

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.


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.

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

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.

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

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.

Promise<PermissionStatus>

A promise resolving to the current PermissionStatus.

import { checkPermissions } from '@tauri-apps/plugin-geolocation';
const permission = await checkPermissions();

2.0.0


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.

Parameter Type Description
channelId number The id returned by watchPosition.

Promise<void>

import { clearWatch } from '@tauri-apps/plugin-geolocation';
await clearWatch(watchId);

2.0.0


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.

Parameter Type Description
options? PositionOptions Configuration for the position request.

Promise<Position>

A promise resolving to the current Position.

import { getCurrentPosition } from '@tauri-apps/plugin-geolocation';
const position = await getCurrentPosition();

2.0.0


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.

Parameter Type Description
permissions | PermissionType[] | null The permissions to request, or null to request all of them.

Promise<PermissionStatus>

A promise resolving to the resulting PermissionStatus.

import { requestPermissions } from '@tauri-apps/plugin-geolocation';
const permission = await requestPermissions(['location']);

2.0.0


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.

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.

Promise<number>

A promise resolving to the id of the registered watcher.

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