Skip to main content
GuidesAPI ReferenceExamplesFAQ

Traffic Events

Estimated reading time: 4 minutes

The Maps SDK for Flutter provides real-time information about traffic events, such as delays, which can occur in various forms.

When enabled and supported by the applied map style, traffic events are visually represented on the map as red overlays on affected road segments.

Based on the source of the event:

  • Most traffic events are provided by the Magic Lane servers if online and provide up-to-date traffic data
  • The user can add custom user-defined roadblocks in order to blacklist certain road segments or areas.

Based on the impact zone:

  • The traffic event can be a path-based traffic area, following the shape of a road.
  • The traffic event can be an area-based traffic area, including a larger geographic area.

The central class for handling both traffic events and roadblocks is TrafficEvent. Instances of this class can be obtained either through user interaction with the map (e.g., selecting a road segment) or as part of user-defined roadblock operations. For route-specific traffic data, the SDK provides the RouteTrafficEvent class, which extends TrafficEvent by including detailed information relevant to a specific route. These events are provided by the route.

Traffic events, including delays and user-defined roadblocks, are fully integrated into the routing and navigation logic. This ensures that calculated routes dynamically account for traffic conditions and any restricted segments.

TrafficEvent structure

The TrafficEvent class has the following structure:

MemberTypeDescription
isRoadblockboolReturns true if the event represents a roadblock.
delayintEstimated delay in seconds. Returns -1 if unknown.
lengthintLength in meters of the road segment affected. Returns -1 if unknown if the event is an area-based roadblock.
impactZoneTrafficEventImpactZoneIndicates if the event affects a point or area.
referencePointCoordinatesThe central coordinate for the event. Returns (0,0) for area events.
boundingBoxRectangleGeographicAreaGeographical bounding box surrounding the event.
descriptionStringHuman-readable description of the traffic event. If it is a user-defined roadblock contains the id
eventClassTrafficEventClassClassification of the traffic event.
eventSeverityTrafficEventSeveritySeverity level of the event.
getImage({size, format})Uint8List?Returns an image representing the traffic event.
imgImgRetrieves the event image in internal format (Img).
previewUrlStringReturns a URL to preview the traffic event. Returns emtpy if not available (user-defined roadblock).
isUserRoadblockboolReturns true if the event is a user-defined roadblock.
affectedTransportModesSet<TrafficTransportMode>Returns all transport modes affected by the event.
startTimeDateTime?UTC start time of the traffic event, if available.
endTimeDateTime?UTC end time of the traffic event, if available.
hasOppositeSiblingboolReturns true if a sibling event exists in the opposite direction. Relevant for path-based events.

RouteTrafficEvent structure

The RouteTrafficEvent class extends TrafficEvent with the following members:

MemberTypeDescription
distanceToDestinationintReturns the distance in meters from the event's position on the route to the destination. Returns 0 if unavailable.
fromCoordinatesThe starting point of the traffic event on the route.
toCoordinatesThe end point of the traffic event on the route.
fromLandmarkPair<Landmark, bool>Returns the starting point as a landmark and a flag indicating if data is cached locally.
toLandmarkPair<Landmark, bool>Returns the end point as a landmark and a flag indicating if data is cached locally.
asyncUpdateToFromData()void Function(GemError)Asynchronously updates the from and to landmarks' address and description info from the server.
cancelUpdate()voidCancels the pending async update request for landmark data.

Usage