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

リアルタイムの運行状況を構成する

リアルタイムの運行状況は、ルート上の運行状況をユーザーに通知し、ユーザーが遭遇した運行状況を報告して確認できるようにする機能の集合です。交通障害の例としては、車両事故、交通渋滞、警察や自動速度取締機の存在、工事、車線規制、特定の気象条件などがあります。このページでは、リアルタイムの運行状況の乱れに関する機能とその構成オプションについて説明します。これには、カスタム ナビゲーション UI を使用するアプリに関する考慮事項も含まれます。

リアルタイムの運行状況に関する機能

Navigation SDK には、コア ナビゲーション エクスペリエンスの一部として、次のリアルタイムの交通情報機能が含まれています。

これらの機能は構成可能で、デフォルトで有効になっています。以降のセクションでは、機能と使用可能な構成オプションについて詳しく説明します。

ルート沿いの運行状況に関するインタラクティブなコールアウト

アプリがルートを表示すると、ルートの概要でもナビゲーション実行中でも、現在の交通情報がルートに沿ってコールアウトとして表示されます。交通状況レイヤを有効にすると、ルート外の交通障害も地図に表示されます。コールアウトには、中断の種類を示すアイコンが含まれています。

ルート沿いのコールアウト

shouldDisplayPrompts を使用して、ルート沿いの運行状況のコールアウトの表示を制御できます。これは、ユーザーが運行状況に近づいたときに自動アラートを表示するかどうかも制御します。

mapView.navigator.shouldDisplayPrompts = true

ユーザーがコールアウトをタップしたときに運行状況の詳細を表示する

運行状況のコールアウトをタップすると、詳細情報が記載された情報カードが開きます。これは、ルート上とルート外の両方のコールアウトに適用されます。ただし、ルート外のコールアウトは、交通状況レイヤが有効になっている場合にのみ表示されます。カードには、障害の種類、最後に報告された時刻、障害がまだ発生しているかどうかを投票するオプション(表示される場合のみ)が表示されます。情報カードの種類と設定オプションは、ユーザーがアクティブなナビゲーションを使用しているかどうかによって異なります。

アクティブなナビゲーションを開始する前の、ルートの概要に表示されるコールアウト情報カード

アクティブなナビを開始する前に、ユーザーは地図またはルートの概要でルート上またはルート外のコールアウトをタップして、情報カードを開くことができます。ルート外のコールアウトを使用するには、交通状況レイヤを有効にする必要があります。情報カードには、運行状況に関する詳細が表示されます。

概要情報カード

showsIncidentCards を使用して、ユーザーがルートの概要で運行状況のコールアウトをタップして詳細情報を表示できるようにするかどうかを制御できます。

mapView.settings.showsIncidentCards = true

ナビゲーション中のコールアウト情報カード

ナビゲーション中に、ユーザーがルート上またはルート外の障害のコールアウトをタップすると、情報カードが開きます。このカードには、障害の種類と最後に報告された時刻が表示されます。また、障害がまだ発生しているかどうかをユーザーが投票するためのボタンも表示されます。

投票は、ユーザーから 5 km 以内のルート上およびルート外の障害(通行止めを除く)に対して行うことができます。Google はこれらの投票を処理して、運行状況の表示を継続するかどうかを判断します。投票は、他の Google マップ ユーザーや Navigation SDK ユーザーの地図にも表示されることがあります。

アクティブなナビゲーション情報カード

shouldDisplayPrompts を使用すると、アクティブなナビゲーション中に、障害コールアウトの表示とタップ操作を制御できます。また、ルート沿いのコールアウトの表示と、ユーザーが障害に近づいたときの自動アラートの表示も制御できます。

mapView.navigator.shouldDisplayPrompts = true

ナビゲーション実行中の投票による交通情報アラートの自動化

アクティブなナビゲーション中に、ユーザーがルート上の障害物に近づくと、障害物に関する情報と、障害物がまだ存在するかどうかを投票するためのボタンを含むプロンプトが表示されます。ユーザーから送信された投票は Google によって処理され、他の Google マップおよび Navigation 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

カスタム レポートボタンを追加する

標準の停止報告ボタンの代わりに、カスタム レポート ボタンを Navigation 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(試験運用版)

Prompt Visibility API を使用すると、Navigation SDK によって生成される UI 要素と独自のカスタム UI 要素との競合を回避できます。この API では、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.
}
...