Khi chế độ chỉ đường được bật và chế độ di chuyển được đặt thành lái xe, Navigation SDK cho iOS sẽ hiển thị một chế độ kiểm soát giới hạn tốc độ ở góc dưới bên trái của bản đồ, cho biết giới hạn tốc độ hiện tại. Nếu người lái xe vượt quá giới hạn tốc độ, chế độ kiểm soát sẽ mở rộng để hiển thị đồng hồ tốc độ bên cạnh màn hình giới hạn tốc độ và kích hoạt cảnh báo khi tốc độ đạt đến một ngưỡng nhất định.
Theo mặc định, Navigation SDK sẽ kích hoạt cảnh báo tốc độ nhỏ khi người lái xe vượt quá giới hạn tốc độ 5 dặm/giờ (hoặc 10 km/giờ) và thay đổi màu của văn bản trên đồng hồ tốc độ thành màu đỏ. Tính năng này sẽ kích hoạt cảnh báo tốc độ cao khi người lái xe vượt quá giới hạn tốc độ 10 dặm/giờ (hoặc 20 km/h) và thay đổi màu nền của đồng hồ tốc độ thành màu đỏ.
Bạn có thể tuỳ chỉnh cả ngưỡng kích hoạt cảnh báo cũng như văn bản và màu nền mà đồng hồ tốc độ hiển thị. Bạn cũng có thể sử dụng Navigation SDK để cung cấp thông tin về tốc độ của người lái xe. Ví dụ: bạn có thể cung cấp thông tin về tốc độ cho các nhà điều hành dịch vụ đi chung xe để giúp họ khuyến khích người lái xe tuân thủ giới hạn tốc độ và cải thiện độ an toàn.
Tuỳ chỉnh ngưỡng cho cảnh báo tốc độ
Bạn có thể tuỳ chỉnh ngưỡng cảnh báo tốc độ cho cả cảnh báo tốc độ nhỏ và lớn dưới dạng tỷ lệ phần trăm so với giới hạn tốc độ hiện tại. Bạn cũng có thể chỉ định khoảng thời gian vượt quá ngưỡng trước khi bản đồ hiển thị cảnh báo.
Ví dụ về mã sau đây đặt ngưỡng cho cảnh báo tốc độ nhỏ là 5% so với giới hạn tốc độ và ngưỡng cho cảnh báo tốc độ lớn là 10% so với giới hạn tốc độ. Thông số này chỉ định rằng bản đồ sẽ hiển thị một cảnh báo sau khi ngưỡng cảnh báo bị vượt quá trong 5 giây.
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.
Tuỳ chỉnh cách đồng hồ tốc độ hiển thị cảnh báo tốc độ
Bạn có thể tuỳ chỉnh màu sắc của màn hình đồng hồ tốc độ cho từng cấp độ cảnh báo.
Bảng sau đây cho biết màu mặc định của cảnh báo tốc độ trong lớp GMSNavigationSpeedometerUIOptions
:
Phần tử | Màu |
---|---|
MinorSpeedAlertBackgroundColorDayMode | 0xffffff(trắng) |
MinorSpeedAlertBackgroundColorNightMode | 0x000000 |
MinorSpeedAlertTextColorDayMode | 0xd93025 |
MinorSpeedAlertTextColorNightMode | 0xd93025 |
MajorSpeedAlertBackgroundColorDayMode | 0xd93025 |
MajorSpeedAlertBackgroundColorNightMode | 0xd93025 |
MajorSpeedAlertTextColorDayMode | 0xffffff(trắng) |
MajorSpeedAlertTextColorNightMode | 0xffffff(trắng) |
Bạn có thể chỉ định màu văn bản và màu nền của đồng hồ tốc độ cho cả cảnh báo tốc độ nhỏ và lớn:
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;
Nhận thông tin về tốc độ từ người lái xe
Nếu ứng dụng của bạn cần chia sẻ thông tin về tốc độ của người lái xe, bạn cũng có thể sử dụng Navigation SDK để cung cấp thông tin về tốc độ của người lái xe. Điều này có thể hữu ích cho các ứng dụng đi chung xe, trong đó nhà điều hành có thể muốn theo dõi tốc độ vượt quá của người lái xe để cải thiện độ an toàn.
Ví dụ: ví dụ sau đây chia sẻ thông tin về tốc độ khi tốc độ vượt quá giới hạn tốc độ một tỷ lệ phần trăm cụ thể:
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 { ... }