Speed warnings
The SDK provides features for monitoring and notifying users about speed limits and violations. You can configure alerts for when a user exceeds the speed limit, when the speed limit changes on the new road segment with respect to the previous, and when the user returns to a normal speed range (onNormalSpeed). The SDK also allows you to set customizable thresholds for speed violations, which can be adjusted for both city and non-city areas. These features help provide timely and relevant speed-related notifications based on the user's location and current speed.
Configure the speed limit listener
class MyCppAlarmListenerImpl : public IAlarmListener {
public:
void onHighSpeed(double limit, bool insideCityArea) override
{
GEM_INFO_LOG(
"Speed limit exceeded %s city area - limit is %.2f m/s",
insideCityArea ? "inside" : "outside",
limit
);
}
void onSpeedLimit(double speed, double limit, bool insideCityArea) override
{
GEM_INFO_LOG(
"New speed limit updated to %.2f m/s (%s city area). Current speed is %.2f m/s",
limit,
insideCityArea ? "inside" : "outside",
speed
);
}
void onNormalSpeed(double limit, bool insideCityArea) override
{
GEM_INFO_LOG(
"Normal speed restored %s city area - limit is %.2f m/s",
insideCityArea ? "inside" : "outside",
limit
);
}
};
auto alarmListener = StrongPointerFactory<MyCppAlarmListenerImpl>();
StrongPointer<AlarmService> alarmService = AlarmService::produce(alarmListener);
The onHighSpeed will continuously send notifications while the user exceeds with a given threshold the maximum speed limit for the current road section.
The onSpeedLimit will be triggered once the current road section has a different speed than the previous road section.
The onNormalSpeed will be triggered once the user speed becomes within the limit of the maximum speed limit for the current road section.
Although the parameter is named insideCityArea, it refers to areas with generally lower speed limits, such as cities, towns, villages, or similar settlements, regardless of their classification.
The limit parameter provided to onSpeedLimit will be 0 if the matched road section does not have a maximum speed limit available or if no road could be found.
Set the threshold for speed
The threshold for the maximum speed excess that triggers the onHighSpeed callback can be configured as follows:
// Trigger onHighSpeed when the speed limit is exceeded by 1 m/s inside a city area
alarmService->setOverSpeedThreshold(1.0, true);
// Trigger onHighSpeed when the speed limit is exceeded by 3 m/s inside a city area
alarmService->setOverSpeedThreshold(3.0, true);
Get the threshold for the speed
The configured threshold can be accessed as follows:
double currentThresholdInsideCity = alarmService->getOverSpeedThreshold(true);
double currentThresholdOutsideCity = alarmService->getOverSpeedThreshold(false);