启用导航且将出行方式设置为驾车时,导航 iOS 版 SDK 在地图左下角显示速度限制控件 会显示当前限速信息如果驾驶员超过速度限制, 控件展开,在限速显示屏旁边显示速度计 在车速达到特定阈值时触发提醒。
默认情况下,导航 SDK 会在驾驶员 超过限速 5 英里/小时(或 10 公里/小时), 速度计文本设为红色。当驾驶员超过四分之一时,此车型就会触发主要限速提醒 限速 10 英里/小时(或 20 公里/小时),并更改速度计背景 颜色变为红色。
您可以自定义触发提醒的阈值,以及 背景颜色。您还可以使用 Navigation SDK 以便为驾驶员提供速度信息。例如,您可以将 向拼车运营商提供速度信息,以帮助他们鼓励 让司机遵守限速要求,提高安全性。
自定义速度提醒阈值
您可以为次要和主要速度自定义速度警报阈值 以超出当前速度限制的百分比形式显示提醒。您还可以 指定超出阈值多长时间之后地图显示提醒。
以下代码示例将次要速度提醒的阈值设置为 5 超出限速的百分比,并将主要限速提醒的阈值设为 10 比速度限制高出的百分比。它指定地图在以下时间后显示警报: 超出提醒阈值达五秒。
Swift
let minorSpeedAlertThresholdPercentage: CGFloat = 0.05 let
majorSpeedAlertThresholdPercentage: CGFloat = 0.1 let
severityUpgradeDurationSeconds: TimeInterval = 5
// Configure SpeedAlertOptions let mutableSpeedAlertOptions:
GMSNavigationMutableSpeedAlertOptions = GMSNavigationMutableSpeedAlertOptions()
mutableSpeedAlertOptions.setSpeedAlertThresholdPercentage(minorSpeedAlertThresholdPercentage,
for: .minor)
mutableSpeedAlertOptions.setSpeedAlertThresholdPercentage(majorSpeedAlertThresholdPercentage,
for: .major) mutableSpeedAlertOptions.severityUpgradeDurationSeconds =
severityUpgradeDurationSeconds
// Set SpeedAlertOptions to Navigator. mapView.navigator?.speedAlertOptions =
mutableSpeedAlertOptions; mapView.navigator?.add(self); // Only needed if
listening to the delegate events.
Objective-C
static const CGFloat minorSpeedAlertThresholdPercentage = 0.05; static const
CGFloat majorSpeedAlertThresholdPercentage = 0.1; static const NSTimeInterval
severityUpgradeDurationSeconds = 5;
// Configure SpeedAlertOptions GMSNavigationMutableSpeedAlertOptions
*mutableSpeedAlertOptions = [[GMSNavigationMutableSpeedAlertOptions alloc]
init]; [mutableSpeedAlertOptions setSpeedAlertThresholdPercentage:
minorSpeedAlertThresholdPercentage
forSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMinor];
[mutableSpeedAlertOptions
setSpeedAlertThresholdPercentage:majorSpeedAlertThresholdPercentage
forSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMajor];
[mutableSpeedAlertOptions
setSeverityUpgradeDurationSeconds:severityUpgradeDurationSeconds];
// Set SpeedAlertOptions to Navigator. mapView.navigator.speedAlertOptions =
mutableSpeedAlertOptions; [mapView.navigator addListener:self]; // Only needed
if listening to the delegate events.
自定义速度计显示速度提醒的方式
您可以为每个警报等级自定义速度计显示的颜色。
下表显示了
GMSNavigationSpeedometerUIOptions
类:
元素 | 颜色 |
---|---|
MinorSpeedAlertBackgroundColorDayMode | 0xffffff(白色) |
MinorSpeedAlertBackgroundColorNightMode | 0x000000 |
MinorSpeedAlertTextColorDayMode | 0xd93025 |
MinorSpeedAlertTextColorNightMode | 0xd93025 |
MajorSpeedAlertBackgroundColorDayMode | 0xd93025 |
MajorSpeedAlertBackgroundColorNightMode | 0xd93025 |
MajorSpeedAlertTextColorDayMode | 0xffffff(白色) |
MajorSpeedAlertTextColorNightMode | 0xffffff(白色) |
你可以同时为小幅值指定速度计的文字和背景颜色 和重大速度提醒:
Swift
let mutableSpeedometerUIOptions: GMSNavigationMutableSpeedometerUIOptions =
GMSNavigationMutableSpeedometerUIOptions()
mutableSpeedometerUIOptions.setTextColor(minorSpeedAlertTextColor, for: .minor,
lightingMode: .normal)
mutableSpeedometerUIOptions.setTextColor(majorSpeedAlertTextColor, for: .major,
lightingMode: .normal)
mutableSpeedometerUIOptions.setBackgroundColor(minorSpeedAlertNightModeBackgroundColor,
for: .minor, lightingMode: .lowLight)
mutableSpeedometerUIOptions.setBackgroundColor(majorSpeedAlertDayModeBackgroundColor,
for: .major, lightingMode: .normal)
mapView.settings.speedometerUIOptions = mutableSpeedometerUIOptions
Objective-C
GMSNavigationMutableSpeedometerUIOptions *mutableSpeedometerUIOptions =
[[GMSNavigationMutableSpeedometerUIOptions alloc] init];
[mutableSpeedometerUIOptions setTextColor: minorSpeedAlertTextColor
forSpeedAlertSeverity: GMSNavigationSpeedAlertSeverityMinor lightingMode:
GMSNavigationLightingModeNormal]; [mutableSpeedometerUIOptions setTextColor:
majorSpeedAlertTextColor forSpeedAlertSeverity:
GMSNavigationSpeedAlertSeverityMajor lightingMode:
GMSNavigationLightingModeNormal]; [mutableSpeedometerUIOptions
setBackgroundColor: minorSpeedAlertNightModeBackgroundColor
forSpeedAlertSeverity: GMSNavigationSpeedAlertSeverityMinor lightingMode:
GMSNavigationLightingModeLowLight]; [mutableSpeedometerUIOptions
setBackgroundColor: majorSpeedAlertDayModeBackgroundColor forSpeedAlertSeverity:
GMSNavigationSpeedAlertSeverityMajor
lightingMode:GMSNavigationLightingModeNormal];
mapView.settings.speedometerUIOptions = mutableSpeedometerUIOptions;
正在从司机处接收速度信息
如果您的应用需要分享有关驾驶员速度的信息,您可以 还使用 Navigation SDK 提供驾驶员的速度信息。 这对于拼车应用非常有用,因为运营商可能希望 监控驾驶员超速以提升安全性。
例如,以下示例会在速度达到 超过速度限制的指定百分比:
Swift
// Listener method for sharing speed information when the speed exceeds the
speed limit by a specified percentage. #pragma mark GMSNavigatorListener func
navigator(_ navigator : GMSNavigator, didUpdateSpeedingPercentage
percentageAboveLimit : Float) { ... }
Objective-C
// Listener method listening to speeding feed. #pragma mark
GMSNavigatorListener - (void)navigator:(GMSNavigator *)navigator
didUpdateSpeedingPercentage:(float)percentageAboveLimit { ... }