เมื่อเปิดใช้การนำทางและตั้งค่าโหมดการเดินทางเป็นขับรถ Navigation SDK สำหรับ iOS จะแสดงตัวควบคุมขีดจำกัดความเร็วที่มุมซ้ายล่างของแผนที่ซึ่งแสดงขีดจำกัดความเร็วปัจจุบัน หากคนขับขับรถเกินขีดจำกัดความเร็ว การควบคุมจะขยายเพื่อแสดงมาตรวัดความเร็วข้างการแสดงขีดจำกัดความเร็ว และทริกเกอร์การแจ้งเตือนเมื่อความเร็วถึงเกณฑ์ที่กำหนด
โดยค่าเริ่มต้น Navigation SDK จะทริกเกอร์การแจ้งเตือนความเร็วเล็กน้อยเมื่อคนขับขับรถเกินขีดจำกัดความเร็ว 5 ไมล์ต่อชั่วโมง (หรือ 10 กม./ชม.) และเปลี่ยนสีข้อความมาตรวัดความเร็วเป็นสีแดง ระบบจะทริกเกอร์การแจ้งเตือนความเร็วสูงเมื่อผู้ขับขี่ขับรถเกินขีดจำกัดความเร็ว 10 ไมล์ต่อชั่วโมง (หรือ 20 กม./ชม.) และเปลี่ยนสีพื้นหลังของมาตรวัดความเร็วเป็นสีแดง
คุณสามารถปรับแต่งทั้งเกณฑ์สำหรับการทริกเกอร์การแจ้งเตือน รวมถึงสีข้อความและสีพื้นหลังที่มาตรวัดความเร็วแสดง นอกจากนี้ คุณยังใช้ Navigation SDK เพื่อแสดงข้อมูลความเร็วของคนขับได้ด้วย ตัวอย่างเช่น คุณสามารถแสดงข้อมูลความเร็วให้ผู้ให้บริการร่วมเดินทางเพื่อช่วยกระตุ้นให้คนขับปฏิบัติตามขีดจำกัดความเร็วและเพิ่มความปลอดภัย
การปรับแต่งเกณฑ์สำหรับการแจ้งเตือนความเร็ว
คุณสามารถปรับแต่งเกณฑ์การแจ้งเตือนความเร็วสำหรับการแจ้งเตือนความเร็วทั้งแบบเล็กน้อยและแบบสำคัญเป็นเปอร์เซ็นต์ที่เกินขีดจำกัดความเร็วของความเร็วปัจจุบัน นอกจากนี้ คุณยังระบุได้ด้วยว่าต้องเกินเกณฑ์เป็นระยะเวลานานเท่าใดก่อนที่แผนที่จะแสดงการแจ้งเตือน
ตัวอย่างโค้ดต่อไปนี้ตั้งค่าเกณฑ์สำหรับการแจ้งเตือนความเร็วเล็กน้อยเป็น 5 เปอร์เซ็นต์เหนือขีดจำกัดความเร็ว และเกณฑ์สำหรับการแจ้งเตือนความเร็วที่สำคัญเป็น 10 เปอร์เซ็นต์เหนือขีดจำกัดความเร็ว ซึ่งระบุว่าแผนที่จะแสดงการแจ้งเตือนหลังจากเกินเกณฑ์การแจ้งเตือนเป็นเวลา 5 วินาที
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 { ... }