配置实时干扰

实时动态是一组功能,可提醒用户其行程中出现的动态,并允许用户报告和验证遇到的动态。干扰情况包括车辆事故、交通拥堵、警察和测速摄像头、施工、车道封闭和特定天气状况。本页介绍了实时干扰功能及其配置选项,包括使用自定义导航界面的应用的注意事项。

实时干扰功能

Navigation SDK 在核心导航体验中包含以下实时干扰功能:

这些功能可配置,默认处于启用状态。以下部分详细介绍了这些功能和可用的配置选项。

路线沿途的交互式干扰提醒

当应用在路线概览或有效导航期间显示路线时,当前的任何中断都会显示为路线上的宣传信息。宣传信息包含一个图标,用于指明中断类型。

沿路线的宣传信息

您可以使用 shouldDisplayPrompts 控制沿路线显示的服务中断宣传信息,该设置还会控制在用户接近服务中断时显示自动提醒

mapView.navigator.shouldDisplayPrompts = true

在用户点按宣传信息时显示中断详情

用户点按宣传信息后,系统会显示一个信息卡片,其中包含有关中断的更多信息,包括中断类型、上次报告的时间,在某些情况下,还会显示一个选项,供用户投票决定中断是否仍存在。系统可能会显示两种不同类型的信息卡片,具体取决于用户是否处于导航状态,并且每种类型的配置选项各不相同。

在开始有效导航之前,路线概览中显示的宣传信息卡片

在开始实时导航之前,当用户点按路线概览中的宣传信息时,系统会显示一条信息卡片,其中包含有关中断情况的更多信息。

“概览”信息卡片

您可以使用 showsIncidentCards 控制用户是否能够点按路线概览中的服务中断宣传信息以显示更多信息。

mapView.settings.showsIncidentCards = true

在有效导航期间显示宣传信息卡片

在导航期间,如果路线上显示了中断提醒,用户可以点按该提醒,系统随即会显示一个信息卡片,其中包含与中断相关的更多信息,包括中断类型和上次报告中断的时间,以及用于投票确定中断是否仍然存在的按钮。Google 会处理用户提交的投票,并可能会在地图上向其他 Google 地图用户和 Navigation SDK 用户显示这些投票,还会根据这些投票来确定是否继续显示相应中断情况。

有效的导航信息卡片

您可以使用 shouldDisplayPrompts 控制在导航期间显示和点按中断宣传信息的功能,该参数还用于控制沿路线显示宣传信息在用户接近中断时显示自动提醒

mapView.navigator.shouldDisplayPrompts = true

在导航期间自动发出干扰提醒并提供投票选项

在导航期间,当用户接近路线上的中断点时,系统会显示一条提示,其中包含中断点的相关信息,以及用于投票确定中断点是否仍然存在的按钮。 Google 会处理用户提交的投票,并可能会在地图上向其他 Google 地图和导航 SDK 用户显示这些投票,还会根据这些投票来确定是否继续显示相应中断情况。

有效的导航信息卡片

您可以使用 shouldDisplayPrompts 配置在主动导航期间显示提醒提示,该命令还用于控制沿路显示宣传信息

mapView.navigator.shouldDisplayPrompts = true

在有效导航期间报告中断

在导航模式处于活跃状态期间,导航界面上会显示一个按钮,供用户报告路线上新的中断情况。当用户点按该按钮时,系统会显示一个菜单,其中包含可报告的干扰类型。Google 会处理用户提交的报告,并可能会在地图上向其他 Google 地图和 Navigation SDK 用户显示这些报告。

“报告”按钮 “报告”菜单

您可以使用 navigationReportIncidentButtonEnabled 配置在活跃导航期间报告按钮的可见性。

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

使用自定义导航界面

如果您实现的 Navigation SDK 包含自定义界面元素,则需要考虑实时干扰元素,以免发生冲突。

报告按钮位置

默认情况下,中断报告按钮位于地图的底部/尾角,对于从左到右书写的语言,位于右侧;对于从右到左书写的语言,位于左侧。如果您需要移动报告按钮以留出空间来放置自定义界面元素,请使用 bottomTrailingButtonsLayoutGuide
// 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
// 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 生成的界面元素与您自己的自定义界面元素之间发生冲突,方法是添加一个监听器,以便在 Navigation SDK 界面元素即将显示和刚刚移除时接收回调。您可以接收实时干扰元素(包括信息卡片、提示和干扰报告菜单)以及 Navigation SDK 生成的其他通知的回调。
// 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.
}
...
// 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.
}
...