הגדרת התראות לגבי מד המהירות

כשהניווט מופעל ואמצעי התחבורה מוגדר לנהיגה, ה-SDK לניווט ל-iOS מציג את הגבלת המהירות בפינה הימנית התחתונה של המפה. אם הנהג חורג ממגבלת המהירות, הרכיב מתרחב ומוצג מד מהירות לצד התצוגה של מגבלת המהירות, ומופעלות התראות כשהמהירות מגיעה לסף מסוים.

כברירת מחדל, Navigation SDK מפעיל התראה על חריגה קלה מהמהירות המותרת כשהנהג חורג ממנה ב-5 מייל לשעה (או ב-10 קמ"ש), ומשנה את הצבע של הטקסט במד המהירות לאדום. היא מפעילה התראה על מהירות גבוהה כשהנהג חורג ממגבלת המהירות ב-16 קמ"ש (או ב-10 מייל לשעה), ומשנה את צבע הרקע של מד המהירות לאדום.

אתם יכולים להתאים אישית את הסף להפעלת ההתראות, את הטקסט ואת צבעי הרקע שמוצגים במד המהירות. אפשר גם להשתמש ב-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 { ... }