กําหนดค่าการแจ้งเตือนมาตรวัดความเร็ว

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