THIS SDK ISDEPRECATED. We rolled out a new and better SDK for you.
Give your users information about traffic incidents so they can adjust their commute according to
the traffic situation.
Sample use case: You are about to drive and you want to avoid roads with traffic incidents on
your way. Use the traffic incident list to have an overview of which streets might be blocked or
congested due to accidents, road works, or possible rain, ice, flooding, etc.
Use the following code snippet to try this in your app.
Copy 1 return IncidentDetailsQueryBuilder . create ( IncidentStyle . S1 , LONDON_BOUNDING_BOX , DEFAULT_ZOOM_LEVEL_FOR_EXAMPLE , "-1" )
2 . withExpandCluster ( true )
Copy 1 IncidentDetailsQueryBuilder . create ( IncidentStyle . S1 , LONDON_BOUNDING_BOX , DEFAULT_ZOOM_LEVEL_FOR_EXAMPLE , TRAFFIC_MODEL_ID )
2 . withExpandCluster ( true )
An example implementation of a listener to the response from the traffic incident details service:
Copy 1 private IncidentDetailsResultListener incidentDetailsResultListener = new IncidentDetailsResultListener ( ) {
3 public void onTrafficIncidentDetailsResult ( IncidentDetailsResponse result ) {
5 final List < TrafficIncidentItem > items = new ArrayList < > ( ) ;
7 TrafficIncidentVisitor visitor = new TrafficIncidentVisitor ( ) {
9 public void visit ( TrafficIncidentCluster cluster ) {
10 items . add ( incidentItemCreator . createClusterOfIncidents ( cluster ) ) ;
14 public void visit ( TrafficIncident incident ) {
15 items . add ( incidentItemCreator . createSingleIncident ( incident ) ) ;
19 for ( BaseTrafficIncident incident : result . getIncidents ( ) ) {
20 incident . accept ( visitor ) ;
23 view . updateTrafficIncidentsList ( items ) ;
27 public void onTrafficIncidentDetailsError ( Throwable error ) {
28 Toast . makeText ( view . getContext ( ) , error . getMessage ( ) , Toast . LENGTH_SHORT ) . show ( ) ;
Copy 1 private val incidentDetailsResultListener = object : IncidentDetailsResultListener {
2 override fun onTrafficIncidentDetailsResult ( result : IncidentDetailsResponse ) {
3 listOfIncidents . clear ( )
6 trafficIncidentItemCreator = TrafficIncidentItemCreator ( ctx )
8 result . incidents . forEach { incident ->
9 incident . accept ( trafficVisitor )
12 trafficIncidentAdapter . updateData ( listOfIncidents )
16 override fun onTrafficIncidentDetailsError ( error : Throwable ) {
17 Toast . makeText ( view ? . context , error . message , Toast . LENGTH_SHORT ) . show ( )
Copy 1 private val trafficVisitor = object : TrafficIncidentVisitor {
3 override fun visit ( cluster : TrafficIncidentCluster ) {
4 listOfIncidents . add ( trafficIncidentItemCreator . createClusterOfIncidents ( cluster ) )
7 override fun visit ( incident : TrafficIncident ) {
8 listOfIncidents . add ( trafficIncidentItemCreator . createSingleIncident ( incident ) )
It is also possible to obtain drawable for every traffic incident. It can be done via '
TrafficIncidentIconProvider' object.
Copy TrafficIncidentIconProvider provider = new TrafficIncidentIconProvider ( incident ) ;
Drawable incidentDrawable = provider . getIcon ( context , TrafficIncidentIconProvider . IconSize . LARGE ) ;
Copy val provider = TrafficIncidentIconProvider ( incident )
val incidentDrawable = provider . getIcon ( context , TrafficIncidentIconProvider . IconSize . LARGE )
Incidents list
Incidents list with clusters