Cuando se habilita la navegación y el modo de viaje se establece en conducción, el SDK de Navigation para iOS muestra un control de límite de velocidad en la esquina inferior izquierda del mapa que muestra el límite de velocidad actual. Si un conductor supera el límite de velocidad, el control se expande para mostrar un velocímetro junto a la pantalla del límite de velocidad y activa alertas cuando la velocidad alcanza un umbral determinado.
De forma predeterminada, el SDK de Navigation activa una alerta de velocidad leve cuando el conductor supera el límite de velocidad en 8 km/h (o 5 mph) y cambia el color del texto del velocímetro a rojo. Se activa una alerta de velocidad grave cuando el conductor supera el límite de velocidad en 16 km/h (10 mph) y cambia el color de fondo del velocímetro a rojo.
Puedes personalizar tanto el umbral para activar las alertas como los colores de texto y de fondo que muestra el velocímetro. También puedes usar el SDK de Navigation para que la información de la velocidad del conductor esté disponible. Por ejemplo, podrías poner a disposición de los operadores de viajes compartidos información sobre la velocidad para ayudarlos a alentar a sus conductores a cumplir con el límite de velocidad y mejorar la seguridad.
Cómo personalizar los umbrales de las alertas de velocidad
Puedes personalizar el umbral de alerta de velocidad para las alertas de velocidad leves y graves como un porcentaje por encima del límite de velocidad actual. También puedes especificar durante cuánto tiempo se supera el umbral antes de que el mapa muestre la alerta.
En el siguiente ejemplo de código, se establece el umbral para una alerta de velocidad menor en un cinco por ciento por encima del límite de velocidad y el umbral para una alerta de velocidad mayor en un 10 por ciento por encima del límite de velocidad. Especifica que el mapa muestra una alerta después de que se supera un umbral de alerta durante cinco segundos.
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.
Cómo personalizar la forma en que el velocímetro muestra las alertas de velocidad
Puedes personalizar los colores de la pantalla del velocímetro para cada nivel de alerta.
En la siguiente tabla, se muestran los colores predeterminados para las alertas de velocidad en la clase GMSNavigationSpeedometerUIOptions
:
Elemento | Color |
---|---|
MinorSpeedAlertBackgroundColorDayMode | 0xffffff(blanco) |
MinorSpeedAlertBackgroundColorNightMode | 0x000000 |
MinorSpeedAlertTextColorDayMode | 0xd93025 |
MinorSpeedAlertTextColorNightMode | 0xd93025 |
MajorSpeedAlertBackgroundColorDayMode | 0xd93025 |
MajorSpeedAlertBackgroundColorNightMode | 0xd93025 |
MajorSpeedAlertTextColorDayMode | 0xffffff(blanco) |
MajorSpeedAlertTextColorNightMode | 0xffffff(blanco) |
Puedes especificar el color del texto y el fondo del velocímetro para las alertas de velocidad leves y graves:
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;
Cómo recibir información sobre la velocidad de los conductores
Si tu aplicación requiere compartir información sobre la velocidad del conductor, también puedes usar el SDK de Navigation para que esté disponible la información sobre la velocidad del conductor. Esto puede ser útil para las aplicaciones de viajes compartidos en las que un operador puede querer supervisar la velocidad excesiva de los conductores para mejorar la seguridad.
Por ejemplo, el siguiente ejemplo comparte información sobre la velocidad cuando esta supera un porcentaje especificado del límite de velocidad:
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 { ... }