プラットフォームを選択: Android iOS

リアルタイムの障害を構成する

リアルタイムの運行状況は、ルート上の運行状況についてユーザーにアラートを送信し、ユーザーが遭遇した運行状況を報告して確認できるようにする機能の集合です。たとえば、車両事故、交通渋滞、警察や自動速度取締機の存在、工事、車線規制、特定の気象条件などが該当します。このページでは、リアルタイムの交通障害機能とその構成オプションについて説明します。カスタム ナビゲーション 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 マップと Navigation SDK のユーザーの地図上に表示されることがあります。

報告ボタン レポート メニュー

標準レポート ボタンの表示と非表示を切り替える

navigationReportIncidentButtonEnabled を使用して、アクティブなナビゲーション中の標準レポート ボタンの表示 / 非表示を設定できます。

// Enables the incident reporting FAB to show in situations where incident
// reporting is possible.
mapView.settings.navigationReportIncidentButtonEnabled = true

カスタムの報告ボタンを追加する

標準の障害レポート ボタンの代わりに、カスタムのレポート ボタンをナビゲーション UI に追加できます。ユーザーがカスタムボタンをクリックすると、presentReportIncidentsPanel メソッドを呼び出してレポート メニューの表示をトリガーできます。カスタムのレポートボタンを追加する前に、reportIncidentsAvailable を呼び出して、アプリがアクティブなナビゲーション中であり、ユーザーがレポートが有効になっている国にいることを確認します。どちらか一方でも該当しない場合、レポート メニューは表示されません。

  // Check if reporting is available before displaying your button
  let isReportingAvailable = mapview.isIncidentReportingAvailable()
  customReportingIncidentButton.isHidden = !isReportingAvailable
  customReportingIncidentButton.addTarget(self, action: #selector(didTapReportIncidentButton), for: .touchUpInside)
  
  // Trigger the reporting flow if the button is clicked
  func didTapReportIncidentButton() {
          mapView.presentReportIncidentsPanel(self) { [weak self] error in
              guard let self = self else { return }
              if let error = error as NSError? {
                  if error.domain == GMSMapViewPresentReportIncidentPanelErrorDomain {
                      let errorCode = GMSMapViewPresentReportIncidentPanelErrorCode(rawValue: error.code)
                      
                      switch errorCode {
                      case .internal:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "An internal error occurred."
                          )
                      case .reportingNotAvailable:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "Reporting is not available."
                          )
                      case .none:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "An unknown error occurred."
                          )
                      }
                  } else {
                      // Handle other potential errors (e.g., network errors)
                      self.showErrorMessage(
                          title: "Error Presenting Report Incident Panel",
                          message: "An unexpected error occurred: \(error.localizedDescription)"
                      )
                  }
              }
              // If error is nil, the panel was presented successfully. You can add any extra logic here.
          }
     }

カスタム ナビゲーション 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(試験運用版)

プロンプトの可視性 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.
}
...