リアルタイムのサービスの停止を構成する
リアルタイムの交通情報は、ルート上の交通情報についてユーザーに警告し、ユーザーが遭遇した交通情報を報告して確認できるようにする一連の機能です。交通渋滞、警察や速度違反取締機の設置、工事、通行止め、特定の天候などの交通障害が該当します。このページでは、リアルタイムの交通情報機能とその構成オプションについて説明します。カスタム ナビゲーション UI を使用するアプリに関する考慮事項も説明します。
リアルタイムの混乱機能
Navigation SDK には、ナビゲーションのコア機能の一部として、次のリアルタイムの交通情報機能が含まれています。これらの機能は構成可能で、デフォルトで有効になっています。以降のセクションでは、機能と使用可能な構成オプションについて詳しく説明します。
経路沿いのインタラクティブな運行情報
アプリがルートを表示する場合(ルートの概要またはナビゲーション実行中)、現在の交通情報はルート上にコールアウトとして表示されます。コールアウトには、中断のタイプを示すアイコンが含まれています。

shouldDisplayPrompts
を使用して、ルート上の交通規制のコールアウトの表示を制御できます。これにより、ユーザーが交通規制に近づいたときの自動アラートの表示も制御されます。
mapView.navigator.shouldDisplayPrompts = true
ユーザーがコールアウトをタップしたときにサービス中断の詳細を表示する
ユーザーがコールアウトをタップすると、サービス停止の種類、最後に報告された時刻など、サービス停止に関する詳細情報が記載された情報カードが表示されます。また、サービス停止がまだ発生しているかどうかを投票するオプションが表示されることもあります。表示される情報カードには、ユーザーがナビゲーションを使用しているかどうかに応じて 2 種類あり、設定オプションはタイプによって異なります。
ルートの概要で、ナビゲーションを開始する前に表示されるコールアウト情報カード
ユーザーがルートの概要でコールアウトをタップすると、ナビゲーションを開始する前に、交通規制に関する詳細情報が記載された情報カードが表示されます。

showsIncidentCards
を使用して、ユーザーがルートの概要でサービス中断のコールアウトをタップして詳細情報を表示する機能を制御できます。
mapView.settings.showsIncidentCards = true
ナビゲーション中のコールアウト情報カード
ナビゲーション中にルート上に交通規制のコールアウトが表示されたら、コールアウトをタップすると、交通規制の種類や最後に報告された時刻などの交通規制の詳細情報と、交通規制がまだ存在するかどうかを投票するためのボタンが表示されます。ユーザーが送信した投票は Google によって処理され、他の Google マップ ユーザーや Navigation SDK ユーザーに地図上に表示される場合があります。また、交通規制を継続して表示するかどうかを判断するために使用されることもあります。

shouldDisplayPrompts
を使用すると、ナビゲーション中の交通規制のコールアウトの表示とタップ可能性を制御できます。これにより、ルート上のコールアウトの表示と、ユーザーが交通規制に近づいたときの自動アラートの表示も制御できます。
mapView.navigator.shouldDisplayPrompts = true
ナビゲーション実行中の投票による交通情報アラートの自動化
ナビゲーションを使用しているときに、ユーザーがルート上の交通規制に近づくと、交通規制に関する情報と、交通規制がまだ存在するかどうかを投票するためのボタンを含むメッセージが表示されます。ユーザーが送信した投票は Google によって処理され、他の Google マップおよびナビゲーション SDK ユーザーの地図に表示される場合があります。また、交通規制を継続して表示するかどうかを判断するために使用されることもあります。

shouldDisplayPrompts
を使用して、ナビゲーション中のアラート プロンプトの表示を構成できます。これにより、ルート上のコールアウトの表示も制御されます。
mapView.navigator.shouldDisplayPrompts = true
ナビゲーション中の交通情報レポート
ナビゲーション モードがアクティブなときに、ナビゲーション UI にボタンが表示されます。このボタンを使用すると、ルート上の新しい交通規制を報告できます。ユーザーがボタンをタップすると、報告可能な中断の種類が表示されます。ユーザーが送信した報告は Google によって処理され、他の Google Maps SDK と Navigation SDK のユーザーが地図上で確認できるようになります。


navigationReportIncidentButtonEnabled
を使用して、アクティブなナビゲーション中の報告ボタンの表示を構成できます。
// Enables the incident reporting FAB to show in situations where incident // reporting is possible. mapView.settings.navigationReportIncidentButtonEnabled = true
カスタム ナビゲーション UI を操作する
Navigation SDK の実装にカスタム UI 要素が含まれている場合は、競合を回避するためにリアルタイムの交通情報要素を検討する必要があります。
報告ボタンの配置
デフォルトでは、サービス停止の報告ボタンは地図の下端/後ろの隅に配置されます(左から右に読む言語の場合は右側、右から左に読む言語の場合は左側)。カスタム UI 要素のスペースを確保するためにレポートボタンを移動する必要がある場合は、bottomTrailingButtonsLayoutGuide
を使用します。Swift
// Create a new layout guide let topRightLayoutGuide = UILayoutGuide() self.view.addLayoutGuide(topRightLayoutGuide) // Activate constraints using fixed constants here as an example // assuming the current reporting button is of fixed height topRightLayoutGuide.topAnchor.constraint(equalTo: _mapView.navigationHeaderLayoutGuide.bottomAnchor, constant: 50).isActive = true topRightLayoutGuide.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: -14).isActive = true // Assign the layout guide _mapView.bottomTrailingButtonsLayoutGuide = topRightLayoutGuide // Create an alternate layout guide to use when the header and the footer are not full width let topRightAlternateLayoutGuide = UILayoutGuide() self.view.addLayoutGuide(topRightAlternateLayoutGuide) // Activate constraints using fixed constants here as an example // assuming the current RTD button is of fixed height topRightAlternateLayoutGuide.topAnchor.constraint(equalTo: _mapView.navigationHeaderLayoutGuide.bottomAnchor, constant: 20).isActive = true topRightAlternateLayoutGuide.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: -10).isActive = true // Assign the layout guide _mapView.bottomTrailingButtonsAlternateLayoutGuide = topRightAlternateLayoutGuide
Objective-C
// Create a new layout guide UILayoutGuide *topRightLayoutGuide = [[UILayoutGuide alloc] init]; [self.view addLayoutGuide:topRightLayoutGuide]; // Activate constraints using fixed constants here as an example // assuming the current RTD button is of fixed height [[topRightLayoutGuide.topAnchor constraintEqualToAnchor:_mapView.navigationHeaderLayoutGuide.bottomAnchor constant:50] setActive:YES]; [[topRightLayoutGuide.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor constant:-14] setActive:YES]; // Assign the layout guide _mapView.bottomTrailingButtonsLayoutGuide = topRightLayoutGuide; // Create an alternate layout guide to use when the header and the footer are not full width UILayoutGuide *topRightAlternateLayoutGuide = [[UILayoutGuide alloc] init]; [self.view addLayoutGuide:topRightAlternateLayoutGuide]; // Activate constraints using fixed constants here as an example // assuming the current RTD button is of fixed height [[topRightAlternateLayoutGuide.topAnchor constraintEqualToAnchor:_mapView.navigationHeaderLayoutGuide.bottomAnchor constant:50] setActive:YES]; [[topRightAlternateLayoutGuide.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor constant:-14] setActive:YES]; // Assign the layout guide _mapView.bottomTrailingButtonsAlternateLayoutGuide = topRightAlternateLayoutGuide;
Prompt Visibility API(試験運用版)
Prompt Visibility API を使用すると、Navigation SDK によって生成された UI 要素と独自のカスタム UI 要素の競合を回避できます。これは、Navigation SDK UI 要素が表示される直前と要素が削除された直後にコールバックを受け取るリスナーを追加することで実現できます。情報カード、プロンプト、交通情報レポート メニューなどのリアルタイムの交通情報要素、および Navigation SDK によって生成されたその他の通知のコールバックを受け取ることができます。Swift
// Additional methods added to GMSNavigatorListener ... func navigatorWillPresentPrompt(_ navigator: GMSNavigator) { // Hide any sort of custom UI element. } func navigatorDidDismissPrompt(_ navigator: GMSNavigator) { // Show any sort of custom UI element. } ...
Objective-C
// Additional methods added to GMSNavigatorListener ... - (void)navigatorWillPresentPrompt:(GMSNavigator *)navigator { // Hide any sort of custom UI element. } - (void)navigatorDidDismissPrompt:(GMSNavigator *)navigator { // Show any sort of custom UI element. } ...