Average speed control sections
An average speed control section is an enforcement zone bounded by an entry gantry and an exit gantry, where the average speed between the two gantries is measured rather than the instantaneous speed. The SDK reports the driver's progress and running average inside such a zone through SpeedSectionAlarm.
For instantaneous speed limit monitoring, see Speed warnings.
Listen for section events
The section callbacks carry no arguments and have to read the sections back from the service. Declare the service before the listener and create it afterwards, which is the pattern the SDK itself documents:
AlarmService? alarmService;
AlarmListener alarmListener = AlarmListener(
onApproachingSpeedSectionAlarms: () {
for (final section in alarmService!.approachingSpeedSectionAlarms) {
showSnackbar("Section control ahead, limit ${section.speedLimit} m/s");
}
},
onEnterSpeedSectionAlarms: () {
showSnackbar("Entered ${alarmService!.speedSectionAlarms.length} section(s)");
},
onTravelSpeedSectionAlarms: () {
for (final section in alarmService!.speedSectionAlarms) {
showSnackbar(
"Average ${section.speedAvg} m/s, ${section.remainingDistance} m left");
}
},
onExitSpeedSectionAlarms: () {
for (final section in alarmService!.exitedSpeedSectionAlarms) {
showSnackbar("Left section, final average ${section.speedAvg} m/s");
}
},
);
alarmService = AlarmService(alarmListener);
Enable section alarms
Section alarms are disabled by default and require the safety cameras overlay to be present in the alarm service overlays collection:
final service = alarmService!;
service.overlays.add(CommonOverlayId.safety.id);
service.enableSpeedSectionAlarm = true;
Check the current state with service.isSpeedSectionAlarmEnabled.
Section alarms are produced only while navigating with a route. They are not emitted in free drive.
Read the active sections
Read the corresponding getter on AlarmService to obtain the sections each notification refers to:
| Callback | Getter to read |
|---|---|
onApproachingSpeedSectionAlarms | approachingSpeedSectionAlarms - sections coming up within the configured alarmDistance. |
onEnterSpeedSectionAlarms | speedSectionAlarms - sections the vehicle is currently inside. |
onTravelSpeedSectionAlarms | speedSectionAlarms - the same sections, with updated progress. |
onExitSpeedSectionAlarms | exitedSpeedSectionAlarms - sections just left behind. |
approachingSpeedSectionAlarms and exitedSpeedSectionAlarms are guaranteed not to be empty when read from their own notification.
speedSectionAlarms carries no such guarantee: it returns the sections currently active, and an empty list when none are. Iterate it rather than indexing into it.
Overlay-based alarms need an active GemMap, and the loaded map style must contain the safety overlay. Without both, the section alarms do not work correctly.
SpeedSectionAlarm
| Property | Type | Description |
|---|---|---|
entry | OverlayItem | The section entry gantry overlay item. |
exit | OverlayItem | The section exit gantry overlay item. |
totalDistance | int | Total enforced section length, in meters. |
remainingDistance | int | Remaining distance to the exit gantry, in meters. |
speedLimit | double | Enforced section speed limit, in meters per second. |
speedAvg | double | Running average speed since the entry gantry, in meters per second. |
Compare speedAvg against speedLimit to warn the driver while there is still distance left to compensate:
for (final section in alarmService!.speedSectionAlarms) {
if (section.speedAvg > section.speedLimit) {
showSnackbar(
"Over the section average, ${section.remainingDistance} m to the exit gantry");
}
}