設定即時中斷
即時交通異常功能是一組功能,可提醒使用者沿途的交通異常狀況,並讓使用者回報及確認所遇到的交通異常狀況。中斷服務的例子包括車禍、交通擁塞、警察和測速照相機、施工、車道封閉和特定天氣狀況。本頁面將說明即時中斷功能及其設定選項,包括使用自訂導覽 UI 的應用程式應考量的事項。
即時中斷功能
Navigation SDK 包含以下實時中斷功能,做為核心導航體驗的一部分:這些功能可設定,且預設為啟用。以下各節將進一步說明這些功能和可用的設定選項。
沿途的互動式中斷說明
應用程式在路線總覽或導航期間顯示路線時,路線上的任何目前中斷情形都會以說明文字的形式顯示。說明文字會附上代表中斷情形類型的圖示。

您可以使用 shouldDisplayPrompts
控管沿途路線的干擾說明顯示方式,這項屬性也會控制使用者接近干擾時,系統是否顯示自動警示。
mapView.navigator.shouldDisplayPrompts = true
在使用者輕觸說明文字時顯示中斷情形詳細資料
使用者輕觸插圖時,系統會顯示資訊卡,提供中斷情形的詳細資訊,包括中斷類型、上次回報時間,以及在某些情況下,讓使用者投票決定中斷情形是否仍在發生。系統可能會顯示兩種資訊卡,這取決於使用者是否處於主動導航狀態,而每種資訊卡的設定選項也各不相同。
路線總覽中的醒目資訊卡,在開始導航前顯示
使用者在開始導航前,輕觸路線總覽中的說明文字時,系統會顯示資訊卡,提供更多關於中斷情形的資訊。

您可以使用 showsIncidentCards
控制使用者在路線總覽中輕觸中斷圖示的功能,以便顯示更多資訊。
mapView.settings.showsIncidentCards = true
在導航期間顯示資訊卡
在導航期間,如果路線上出現中斷資訊說明,使用者可以輕觸該說明,顯示資訊卡,提供中斷情形的更多資訊,包括中斷類型和上次回報時間,以及可投票表達中斷情形是否仍存在的按鈕。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
使用自訂導覽 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. } ...