diff --git a/src/content/docs/ja/plugin/geolocation.mdx b/src/content/docs/ja/plugin/geolocation.mdx new file mode 100644 index 0000000000..01ea26f17a --- /dev/null +++ b/src/content/docs/ja/plugin/geolocation.mdx @@ -0,0 +1,183 @@ +--- +title: Geolocation(位置情報) +description: デバイスの現在の位置情報(利用可能であれば高度・方位・速度に関する情報も)を取得して追跡します。 +plugin: geolocation +i18nReady: true +--- + +import PluginLinks from '@components/PluginLinks.astro'; +import Compatibility from '@components/plugins/Compatibility.astro'; + +import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; +import PluginPermissions from '@components/PluginPermissions.astro'; +import TranslationNote from '@components/i18n/TranslationNote.astro'; + + + +**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。 + + + + + +デバイスの現在の位置情報を取得し(利用可能であれば、高度・方位・速度に関する情報も)追跡します。 + +## 対応プラットフォーム + + + +## セットアップ + +はじめに、「geolocation 位置情報」プラグインをインストールしてください。 + + + + + 自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します: + + {' '} + + + + + + + + 1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します: + + ```sh frame=none + cargo add tauri-plugin-geolocation --target 'cfg(any(target_os = "android", target_os = "ios"))' + ``` + + 2. 追加したプラグインを初期化するために `lib.rs` を修正します: + + ```rust title="src-tauri/src/lib.rs" ins={5-6} + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + .setup(|app| { + #[cfg(mobile)] + app.handle().plugin(tauri_plugin_geolocation::init()); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします: + + + + + + + + +## 設定 + +### iOS + +Apple は、位置情報に関して Info.plist にプライバシー関連の記述を行なうことを義務付けています。これには、アプリが位置情報にアクセスする必要がある理由を記述する必要があります。以下に記述例を示します: + +```xml {6-7} + + + + + NSLocationWhenInUseUsageDescription + Required to do XY + + +``` + +### Android + +このプラグインは、`AndroidManifest.xml` ファイルに以下のアクセス権限を自動的に追加します: + +```xml + + +``` + +あなたのアプリが GPS 機能を必要とする場合は、`AndroidManifest.xml` ファイルに次の記述を追加する必要があります: + +```xml + +``` + +Google Play ストアは、GPS 機能を有していないデバイスにこのアプリを表示するかどうかを判定するために、このプロパティ値を使用します。 + +## 使用法 + +「geolocation」プラグインは JavaScript で利用できます。 + +```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); + } + ); +} +``` + +## アクセス権限 Permissions + +デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、`capabilities` 設定でアクセス権限を変更する必要があります。 + +詳細については「[セキュリティ・レベル Capabilities](/ja/security/capabilities/)」の章を参照してください。また、プラグインのアクセス権限を設定するには「[プライグン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」の章のステップ・バイ・ステップ・ガイドを参照してください。 + +```json title="src-tauri/capabilities/mobile.json" ins={7-11} +{ + "$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" + ] +} +``` + + + +
+ 【※ この日本語版は、「Nov 21, 2025 英語版」に基づいています】 +