เมื่อเปิดใช้การนำทางและตั้งค่าโหมดการเดินทางเป็นขับรถ 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 { ... }