コンテンツにスキップ
Tauri

ジオロケーション

高度、方角、速度(利用可能な場合)に関する情報を含む、デバイスの現在位置を取得および追跡します。

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

ジオロケーションプラグインをインストールして開始します。

プロジェクトのパッケージマネージャーを使用して依存関係を追加します。

npm run tauri add geolocation

Apple は、Info.plist に位置情報のプライバシー説明を指定することを要求しています。ここでは、アプリがそれにアクセスする必要がある理由を説明する必要があります。以下は説明の例です。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>XY を実行するために必要です</string>
</dict>
</plist>

このプラグインは、AndroidManifest.xml ファイルに次の権限を自動的に追加します。

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

アプリが機能するために GPS 機能が必要な場合は、AndroidManifest.xml ファイルに以下を追加する必要があります。

<uses-feature android:name="android.hardware.location.gps" android:required="true" />

Google Play ストアは、このプロパティを使用して、GPS 機能のないデバイスにアプリを表示するかどうかを決定します。

ジオロケーションプラグインは JavaScript で利用できます。

import {
checkPermissions,
requestPermissions,
getCurrentPosition,
watchPosition,
} from '@tauri-apps/plugin-geolocation';
let permissions = await checkPermissions();
if (
permissions.location === 'prompt' ||
permissions.location === 'prompt-with-rationale'
) {
permissions = await requestPermissions(['location']);
}
if (permissions.location === 'granted') {
const pos = await getCurrentPosition();
await watchPosition(
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
(pos) => {
console.log(pos);
}
);
}

デフォルトでは、すべての潜在的に危険なプラグインコマンドとスコープはブロックされており、アクセスできません。これらを有効にするには、capabilities 設定の権限を変更する必要があります。

詳細については、機能の概要 と、プラグイン権限を使用するための ステップバイステップガイド を参照してください。

src-tauri/capabilities/mobile.json
{
"$schema": "../gen/schemas/mobile-schema.json",
"identifier": "mobile-capability",
"windows": ["main"],
"platforms": ["iOS", "android"],
"permissions": [
"core:default",
"geolocation:allow-check-permissions",
"geolocation:allow-request-permissions",
"geolocation:allow-get-current-position",
"geolocation:allow-watch-position"
]
}

Permission Table

Identifier Description

geolocation:allow-check-permissions

Enables the check_permissions command without any pre-configured scope.

geolocation:deny-check-permissions

Denies the check_permissions command without any pre-configured scope.

geolocation:allow-clear-permissions

Enables the clear_permissions command without any pre-configured scope.

geolocation:deny-clear-permissions

Denies the clear_permissions command without any pre-configured scope.

geolocation:allow-clear-watch

Enables the clear_watch command without any pre-configured scope.

geolocation:deny-clear-watch

Denies the clear_watch command without any pre-configured scope.

geolocation:allow-get-current-position

Enables the get_current_position command without any pre-configured scope.

geolocation:deny-get-current-position

Denies the get_current_position command without any pre-configured scope.

geolocation:allow-request-permissions

Enables the request_permissions command without any pre-configured scope.

geolocation:deny-request-permissions

Denies the request_permissions command without any pre-configured scope.

geolocation:allow-watch-position

Enables the watch_position command without any pre-configured scope.

geolocation:deny-watch-position

Denies the watch_position command without any pre-configured scope.


© 2025 Tauri Contributors. CC-BY / MIT