Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Lorsque la navigation est activée et que le mode de déplacement est défini sur "En voiture", le SDK Navigation pour iOS affiche une commande de limitation de vitesse en bas à gauche de la carte, qui indique la limitation de vitesse actuelle. Si un conducteur dépasse la limite de vitesse, le contrôle se développe pour afficher un compteur de vitesse à côté de la limite de vitesse et déclenche des alertes lorsque la vitesse atteint un certain seuil.
Par défaut, le SDK Navigation déclenche une alerte de vitesse mineure lorsque le conducteur dépasse la limite de vitesse de 8 km/h (ou 16 km/h) et change la couleur du texte du compteur de vitesse en rouge. Elle déclenche une alerte de vitesse majeure lorsque le conducteur dépasse la limite de vitesse de 16 km/h (ou 20 km/h) et change la couleur de fond du compteur de vitesse en rouge.
Vous pouvez personnaliser le seuil de déclenchement des alertes, ainsi que le texte et les couleurs d'arrière-plan affichés par le compteur de vitesse. Vous pouvez également utiliser le SDK Navigation pour rendre les informations sur la vitesse du conducteur disponibles. Par exemple, vous pouvez mettre à la disposition des opérateurs de covoiturage des informations sur la vitesse pour les aider à encourager leurs conducteurs à respecter les limitations de vitesse et à améliorer la sécurité.
Personnaliser les seuils des alertes de vitesse
Vous pouvez personnaliser le seuil d'alerte de vitesse pour les alertes de vitesse mineures et majeures en tant que pourcentage au-dessus de la limite de vitesse actuelle. Vous pouvez également spécifier la durée pendant laquelle le seuil est dépassé avant que l'alerte ne s'affiche sur la carte.
L'exemple de code suivant définit le seuil d'une alerte de vitesse mineure à 5 % au-dessus de la limite de vitesse et le seuil d'une alerte de vitesse majeure à 10 % au-dessus de la limite de vitesse. Il indique que la carte affiche une alerte après que le seuil d'alerte a été dépassé pendant cinq secondes.
Swift
letminorSpeedAlertThresholdPercentage:CGFloat=0.05letmajorSpeedAlertThresholdPercentage:CGFloat=0.1letseverityUpgradeDurationSeconds: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 iflisteningtothedelegateevents.
Objective-C
staticconstCGFloatminorSpeedAlertThresholdPercentage=0.05;staticconstCGFloatmajorSpeedAlertThresholdPercentage=0.1;staticconstNSTimeIntervalseverityUpgradeDurationSeconds=5;// Configure SpeedAlertOptions GMSNavigationMutableSpeedAlertOptions*mutableSpeedAlertOptions=[[GMSNavigationMutableSpeedAlertOptionsalloc]init];[mutableSpeedAlertOptionssetSpeedAlertThresholdPercentage:minorSpeedAlertThresholdPercentageforSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMinor];[mutableSpeedAlertOptionssetSpeedAlertThresholdPercentage:majorSpeedAlertThresholdPercentageforSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMajor];[mutableSpeedAlertOptionssetSeverityUpgradeDurationSeconds:severityUpgradeDurationSeconds];// Set SpeedAlertOptions to Navigator. mapView.navigator.speedAlertOptions =mutableSpeedAlertOptions;[mapView.navigatoraddListener:self];// Only needediflisteningtothedelegateevents.
Personnaliser l'affichage des alertes de vitesse sur le compteur de vitesse
Vous pouvez personnaliser les couleurs de l'indicateur de vitesse pour chaque niveau d'alerte.
Le tableau suivant indique les couleurs par défaut des alertes de vitesse dans la classe GMSNavigationSpeedometerUIOptions :
Élément
Couleur
MinorSpeedAlertBackgroundColorDayMode
0xffffff(blanc)
MinorSpeedAlertBackgroundColorNightMode
0x000000
MinorSpeedAlertTextColorDayMode
0xd93025
MinorSpeedAlertTextColorNightMode
0xd93025
MajorSpeedAlertBackgroundColorDayMode
0xd93025
MajorSpeedAlertBackgroundColorNightMode
0xd93025
MajorSpeedAlertTextColorDayMode
0xffffff(blanc)
MajorSpeedAlertTextColorNightMode
0xffffff(blanc)
Vous pouvez spécifier la couleur du texte et de l'arrière-plan du compteur de vitesse pour les alertes de vitesse mineures et majeures :
Recevoir des informations sur la vitesse des conducteurs
Si votre application nécessite de partager des informations sur la vitesse du conducteur, vous pouvez également utiliser le SDK Navigation pour les rendre disponibles.
Cela peut être utile pour les applications de covoiturage dans lesquelles un opérateur peut souhaiter surveiller les excès de vitesse des conducteurs pour améliorer la sécurité.
Par exemple, l'exemple suivant partage des informations sur la vitesse lorsque celle-ci dépasse la limite de vitesse d'un pourcentage spécifié :
Swift
// Listener method for sharing speed information when the speed exceeds thespeedlimitbyaspecifiedpercentage.#pragmamarkGMSNavigatorListenerfuncnavigator(_navigator:GMSNavigator,didUpdateSpeedingPercentagepercentageAboveLimit:Float){...}
Objective-C
// Listener method listening to speeding feed. #pragma markGMSNavigatorListener-(void)navigator:(GMSNavigator*)navigatordidUpdateSpeedingPercentage:(float)percentageAboveLimit{...}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eWhen navigation is in driving mode, the Navigation SDK displays the current speed limit and driver's speed, providing visual and configurable speed alerts.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can customize the thresholds for minor and major speed alerts, including the percentage over the speed limit and duration before triggering.\u003c/p\u003e\n"],["\u003cp\u003eThe speedometer's text and background colors can be customized for day and night modes, allowing for clear visual distinction of speed alert levels.\u003c/p\u003e\n"],["\u003cp\u003eThe Navigation SDK enables access to the driver's speed information, which can be used for purposes like monitoring driver behavior in rideshare applications.\u003c/p\u003e\n"]]],["The Navigation SDK for iOS displays a speed limit and speedometer when driving. Speed alerts are triggered when the driver exceeds the limit. Minor alerts occur at 5 mph (or 10 kph) over, turning the text red. Major alerts occur at 10 mph (or 20 kph) over, turning the background red. Alert thresholds and colors are customizable, including percentages over the limit and time before the alert. The SDK also provides driver speed data for monitoring purposes, such as in rideshare apps.\n"],null,["# Configure speedometer alerts\n\nWhen navigation is enabled and the travel mode is set to driving, the Navigation\nSDK for iOS displays a speed limit control in the lower left corner of the map\nthat shows the current speed limit. If a driver exceeds the speed limit, the\ncontrol expands to display a speedometer next to the speed limit display and\ntriggers alerts when the speed reaches a certain threshold.\n\nBy default, the Navigation SDK triggers a minor speed alert when the driver\nexceeds the speed limit by 5 mph (or 10 kph), and changes the color of the\nspeedometer text to red. It triggers a major speed alert when the driver exceeds\nthe speed limit by 10 mph (or 20 kph), and changes the speedometer background\ncolor to red. \n\nYou can customize both the threshold for triggering the alerts and the text and\nbackground colors the speedometer displays. You can also use the Navigation SDK\nto make the driver's speed information available. For example, you could make\nspeed information available to rideshare operators to help them encourage their\ndrivers to adhere to the speed limit and improve safety.\n\nCustomizing thresholds for speed alerts\n---------------------------------------\n\nYou can customize the speed alert threshold for both minor and major speed\nalerts as a percentage over the speed limit of the current speed. You can also\nspecify how long the threshold is exceeded before the map displays the alert.\n\nThe following code example sets the threshold for a minor speed alert to five\npercent over the speed limit, and the threshold for a major speed alert to 10\npercent over the speed limit. It specifies that the map displays an alert after\nan alert threshold has been exceeded for five seconds.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let minorSpeedAlertThresholdPercentage: CGFloat = 0.05 let\n majorSpeedAlertThresholdPercentage: CGFloat = 0.1 let\n severityUpgradeDurationSeconds: TimeInterval = 5\n\n // Configure SpeedAlertOptions let mutableSpeedAlertOptions:\n GMSNavigationMutableSpeedAlertOptions = GMSNavigationMutableSpeedAlertOptions()\n mutableSpeedAlertOptions.setSpeedAlertThresholdPercentage(minorSpeedAlertThresholdPercentage,\n for: .minor)\n mutableSpeedAlertOptions.setSpeedAlertThresholdPercentage(majorSpeedAlertThresholdPercentage,\n for: .major) mutableSpeedAlertOptions.severityUpgradeDurationSeconds =\n severityUpgradeDurationSeconds\n\n // Set SpeedAlertOptions to Navigator. mapView.navigator?.speedAlertOptions =\n mutableSpeedAlertOptions; mapView.navigator?.add(self); // Only needed if\n listening to the delegate events.\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n static const CGFloat minorSpeedAlertThresholdPercentage = 0.05; static const\n CGFloat majorSpeedAlertThresholdPercentage = 0.1; static const NSTimeInterval\n severityUpgradeDurationSeconds = 5;\n\n // Configure SpeedAlertOptions GMSNavigationMutableSpeedAlertOptions\n *mutableSpeedAlertOptions = [[GMSNavigationMutableSpeedAlertOptions alloc]\n init]; [mutableSpeedAlertOptions setSpeedAlertThresholdPercentage:\n minorSpeedAlertThresholdPercentage\n forSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMinor];\n [mutableSpeedAlertOptions\n setSpeedAlertThresholdPercentage:majorSpeedAlertThresholdPercentage\n forSpeedAlertSeverity:GMSNavigationSpeedAlertSeverityMajor];\n [mutableSpeedAlertOptions\n setSeverityUpgradeDurationSeconds:severityUpgradeDurationSeconds];\n\n // Set SpeedAlertOptions to Navigator. mapView.navigator.speedAlertOptions =\n mutableSpeedAlertOptions; [mapView.navigator addListener:self]; // Only needed\n if listening to the delegate events.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nCustomizing how the speedometer displays speed alerts\n-----------------------------------------------------\n\nYou can customize the colors of the speedometer display for each alert level.\n\nThe following table shows the default colors for speed alerts in the\n`GMSNavigationSpeedometerUIOptions` class:\n\n| Element | Color |\n|-----------------------------------------|-----------------|\n| MinorSpeedAlertBackgroundColorDayMode | 0xffffff(white) |\n| MinorSpeedAlertBackgroundColorNightMode | 0x000000 |\n| MinorSpeedAlertTextColorDayMode | 0xd93025 |\n| MinorSpeedAlertTextColorNightMode | 0xd93025 |\n| MajorSpeedAlertBackgroundColorDayMode | 0xd93025 |\n| MajorSpeedAlertBackgroundColorNightMode | 0xd93025 |\n| MajorSpeedAlertTextColorDayMode | 0xffffff(white) |\n| MajorSpeedAlertTextColorNightMode | 0xffffff(white) |\n\nYou can specify the text and background color of the speedometer for both minor\nand major speed alerts:\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let mutableSpeedometerUIOptions: GMSNavigationMutableSpeedometerUIOptions =\n GMSNavigationMutableSpeedometerUIOptions()\n mutableSpeedometerUIOptions.setTextColor(minorSpeedAlertTextColor, for: .minor,\n lightingMode: .normal)\n mutableSpeedometerUIOptions.setTextColor(majorSpeedAlertTextColor, for: .major,\n lightingMode: .normal)\n mutableSpeedometerUIOptions.setBackgroundColor(minorSpeedAlertNightModeBackgroundColor,\n for: .minor, lightingMode: .lowLight)\n mutableSpeedometerUIOptions.setBackgroundColor(majorSpeedAlertDayModeBackgroundColor,\n for: .major, lightingMode: .normal)\n\n mapView.settings.speedometerUIOptions = mutableSpeedometerUIOptions\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n GMSNavigationMutableSpeedometerUIOptions *mutableSpeedometerUIOptions =\n [[GMSNavigationMutableSpeedometerUIOptions alloc] init];\n [mutableSpeedometerUIOptions setTextColor: minorSpeedAlertTextColor\n forSpeedAlertSeverity: GMSNavigationSpeedAlertSeverityMinor lightingMode:\n GMSNavigationLightingModeNormal]; [mutableSpeedometerUIOptions setTextColor:\n majorSpeedAlertTextColor forSpeedAlertSeverity:\n GMSNavigationSpeedAlertSeverityMajor lightingMode:\n GMSNavigationLightingModeNormal]; [mutableSpeedometerUIOptions\n setBackgroundColor: minorSpeedAlertNightModeBackgroundColor\n forSpeedAlertSeverity: GMSNavigationSpeedAlertSeverityMinor lightingMode:\n GMSNavigationLightingModeLowLight]; [mutableSpeedometerUIOptions\n setBackgroundColor: majorSpeedAlertDayModeBackgroundColor forSpeedAlertSeverity:\n GMSNavigationSpeedAlertSeverityMajor\n lightingMode:GMSNavigationLightingModeNormal];\n\n mapView.settings.speedometerUIOptions = mutableSpeedometerUIOptions;\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nReceiving speed information from drivers\n----------------------------------------\n\nIf your application requires sharing information about driver speed, you can\nalso use the Navigation SDK to make the driver's speed information available.\nThis can be useful for rideshare applications in which an operator may want to\nmonitor excessive speeding by drivers to improve safety.\n\nFor example, the following example shares speed information when the speed is a\nspecified percentage over the speed limit:\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n // Listener method for sharing speed information when the speed exceeds the\n speed limit by a specified percentage. #pragma mark GMSNavigatorListener func\n navigator(_ navigator : GMSNavigator, didUpdateSpeedingPercentage\n percentageAboveLimit : Float) { ... }\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n // Listener method listening to speeding feed. #pragma mark\n GMSNavigatorListener - (void)navigator:(GMSNavigator *)navigator\n didUpdateSpeedingPercentage:(float)percentageAboveLimit { ... }\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]