はじめに
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-launch-navigator`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/ja/docs/plugins/launch-navigator/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
Section titled “インストール”npm install @capgo/capacitor-launch-navigatornpx cap syncyarn add @capgo/capacitor-launch-navigatornpx cap syncpnpm add @capgo/capacitor-launch-navigatornpx cap syncbun add @capgo/capacitor-launch-navigatornpx cap syncプラットフォーム設定
Section titled “プラットフォーム設定”Info.plistにURLスキームを追加して、インストールされているナビゲーションアプリを検出します:
<key>LSApplicationQueriesSchemes</key><array> <string>googlemaps</string> <string>waze</string> <string>citymapper</string> <string>transit</string> <string>moovit</string> <string>uber</string> <string>lyft</string></array>Android
Section titled “Android”追加の設定は不要です。プラグインは自動的にインストールされているナビゲーションアプリを検出します。
import { LaunchNavigator, TransportMode } from '@capgo/capacitor-launch-navigator';
// 座標への基本的なナビゲーションawait LaunchNavigator.navigate({ destination: [37.7749, -122.4194], // サンフランシスコの座標});
// オプション付きの高度なナビゲーションawait LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { start: [37.7849, -122.4094], // オプションの開始地点 transportMode: TransportMode.DRIVING, app: 'google_maps', // 優先ナビゲーションアプリ appDisplayName: 'Google Maps' }});
// 特定のアプリが利用可能かチェックconst result = await LaunchNavigator.isAppAvailable({ app: 'google_maps'});
if (result.available) { console.log('Google Maps is installed');} else { console.log('Google Maps is not available');}
// すべての利用可能なナビゲーションアプリを取得const availableApps = await LaunchNavigator.getAvailableApps();console.log('Available navigation apps:', availableApps);
// プラットフォームでサポートされているすべてのアプリを取得const supportedApps = await LaunchNavigator.getSupportedApps();console.log('Supported apps:', supportedApps);APIリファレンス
Section titled “APIリファレンス”navigate(options)
Section titled “navigate(options)”navigate(options: NavigateOptions) => Promise<void>指定された座標へのナビゲーションを起動します。
| パラメータ | タイプ |
|---|---|
options | NavigateOptions |
isAppAvailable(options)
Section titled “isAppAvailable(options)”isAppAvailable(options: { app: string }) => Promise<{ available: boolean }>特定のナビゲーションアプリがインストールされているかチェックします。
| パラメータ | タイプ |
|---|---|
options | { app: string } |
戻り値: Promise<{ available: boolean }>
getAvailableApps()
Section titled “getAvailableApps()”getAvailableApps() => Promise<{ apps: string[] }>デバイス上のすべての利用可能なナビゲーションアプリのリストを取得します。
戻り値: Promise<{ apps: string[] }>
getSupportedApps()
Section titled “getSupportedApps()”getSupportedApps() => Promise<{ apps: string[] }>現在のプラットフォームでサポートされているすべてのアプリのリストを取得します。
戻り値: Promise<{ apps: string[] }>
インターフェース
Section titled “インターフェース”NavigateOptions
Section titled “NavigateOptions”| プロパティ | タイプ | 説明 |
|---|---|---|
destination | [number, number] | 目的地の座標 [緯度, 経度] |
options | NavigationOptions | 追加のナビゲーションオプション(オプション) |
NavigationOptions
Section titled “NavigationOptions”| プロパティ | タイプ | 説明 |
|---|---|---|
start | [number, number] | 開始座標 [緯度, 経度] (オプション) |
transportMode | TransportMode | 交通手段(オプション) |
app | string | 優先ナビゲーションアプリ(オプション) |
appDisplayName | string | アプリの表示名(オプション) |
TransportMode
Section titled “TransportMode”enum TransportMode { DRIVING = 'driving', WALKING = 'walking', TRANSIT = 'transit', CYCLING = 'cycling'}重要: このプラグインはナビゲーションに緯度/経度座標のみを受け入れます。住所を座標に変換するには@capgo/capacitor-nativegeocoderを使用してください。
import { NativeGeocoder } from '@capgo/capacitor-nativegeocoder';import { LaunchNavigator } from '@capgo/capacitor-launch-navigator';
// 住所を座標に変換const geocodeResult = await NativeGeocoder.forwardGeocode({ address: '1600 Amphitheatre Parkway, Mountain View, CA'});
if (geocodeResult.results.length > 0) { const coords = geocodeResult.results[0];
// ジオコーディングされた座標でナビゲーションを起動 await LaunchNavigator.navigate({ destination: [coords.latitude, coords.longitude] });}サポートされているナビゲーションアプリ
Section titled “サポートされているナビゲーションアプリ”- Apple Maps(組み込み)
- Google Maps
- Waze
- Citymapper
- Transit
- Moovit
- Uber
- Lyft
- その他多数…
Android
Section titled “Android”- Google Maps(組み込み)
- Waze
- Citymapper
- HERE WeGo
- Sygic
- MapQuest
- Moovit
- その他多数…
複数のアプリをチェックして最初に利用可能なものを使用
Section titled “複数のアプリをチェックして最初に利用可能なものを使用”const appsToCheck = ['google_maps', 'waze', 'apple_maps'];let selectedApp = null;
for (const app of appsToCheck) { const result = await LaunchNavigator.isAppAvailable({ app }); if (result.available) { selectedApp = app; break; }}
if (selectedApp) { await LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { app: selectedApp } });} else { console.log('No supported navigation apps found');}ナビゲーションアプリのユーザー選択
Section titled “ナビゲーションアプリのユーザー選択”// 利用可能なアプリを取得const { apps } = await LaunchNavigator.getAvailableApps();
if (apps.length === 0) { alert('No navigation apps available'); return;}
// ユーザーにアプリ選択を表示(疑似コード)const selectedApp = await showAppSelectionDialog(apps);
// 選択したアプリでナビゲートawait LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { app: selectedApp }});異なる交通手段でのナビゲーション
Section titled “異なる交通手段でのナビゲーション”// 車での道順await LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { transportMode: TransportMode.DRIVING }});
// 徒歩での道順await LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { transportMode: TransportMode.WALKING }});
// 公共交通機関での道順await LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { transportMode: TransportMode.TRANSIT }});ベストプラクティス
Section titled “ベストプラクティス”- ナビゲーションを試みる前に常にアプリの可用性をチェックする
- 優先アプリが利用できない場合のフォールバックオプションを提供する
- ユーザー選択に意味のあるアプリ表示名を使用する
- ユーザーフレンドリーなメッセージでエラーを適切に処理する
- デフォルトのナビゲーションアプリのユーザー設定を考慮する
- iOSとAndroidの両方のデバイスでテストする
- 無効な座標に対する適切なエラーハンドリングを実装する
エラーハンドリング
Section titled “エラーハンドリング”try { await LaunchNavigator.navigate({ destination: [37.7749, -122.4194], options: { app: 'google_maps', transportMode: TransportMode.DRIVING } });} catch (error) { console.error('Navigation failed:', error); // エラーを処理 - アプリが利用できない、座標が無効など alert('Unable to launch navigation. Please check your coordinates and try again.');}ユースケース
Section titled “ユースケース”- 位置情報ベースのサービス: ユーザーを目的地にナビゲート
- 配達アプリ: ドライバーを配達場所に案内
- イベントアプリ: 参加者を会場の場所に誘導
- 不動産アプリ: 物件の場所にナビゲート
- 旅行アプリ: 観光客を観光地に案内
- サービスアプリ: 現場作業員を作業現場に誘導