THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Traffic incident list

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.

1return IncidentDetailsQueryBuilder.create(IncidentStyle.S1, LONDON_BOUNDING_BOX, DEFAULT_ZOOM_LEVEL_FOR_EXAMPLE, "-1")
2 .withExpandCluster(true)
3 .build()
1IncidentDetailsQueryBuilder.create(IncidentStyle.S1, LONDON_BOUNDING_BOX, DEFAULT_ZOOM_LEVEL_FOR_EXAMPLE, TRAFFIC_MODEL_ID)
2 .withExpandCluster(true)
3 .build()

An example implementation of a listener to the response from the traffic incident details service:

1private IncidentDetailsResultListener incidentDetailsResultListener = new IncidentDetailsResultListener() {
2 @Override
3 public void onTrafficIncidentDetailsResult(IncidentDetailsResponse result) {
4
5 final List<TrafficIncidentItem> items = new ArrayList<>();
6
7 TrafficIncidentVisitor visitor = new TrafficIncidentVisitor() {
8 @Override
9 public void visit(TrafficIncidentCluster cluster) {
10 items.add(incidentItemCreator.createClusterOfIncidents(cluster));
11 }
12
13 @Override
14 public void visit(TrafficIncident incident) {
15 items.add(incidentItemCreator.createSingleIncident(incident));
16 }
17 };
18
19 for (BaseTrafficIncident incident : result.getIncidents()) {
20 incident.accept(visitor);
21 }
22
23 view.updateTrafficIncidentsList(items);
24 }
25
26 @Override
27 public void onTrafficIncidentDetailsError(Throwable error) {
28 Toast.makeText(view.getContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
29 }
30};
1private val incidentDetailsResultListener = object : IncidentDetailsResultListener {
2 override fun onTrafficIncidentDetailsResult(result: IncidentDetailsResponse) {
3 listOfIncidents.clear()
4
5 context?.let { ctx ->
6 trafficIncidentItemCreator = TrafficIncidentItemCreator(ctx)
7
8 result.incidents.forEach { incident ->
9 incident.accept(trafficVisitor)
10 }
11
12 trafficIncidentAdapter.updateData(listOfIncidents)
13 }
14 }
15
16 override fun onTrafficIncidentDetailsError(error: Throwable) {
17 Toast.makeText(view?.context, error.message, Toast.LENGTH_SHORT).show()
18 }
19}
1private val trafficVisitor = object : TrafficIncidentVisitor {
2
3 override fun visit(cluster: TrafficIncidentCluster) {
4 listOfIncidents.add(trafficIncidentItemCreator.createClusterOfIncidents(cluster))
5 }
6
7 override fun visit(incident: TrafficIncident) {
8 listOfIncidents.add(trafficIncidentItemCreator.createSingleIncident(incident))
9 }
10}

It is also possible to obtain drawable for every traffic incident. It can be done via ' TrafficIncidentIconProvider' object.

TrafficIncidentIconProvider provider = new TrafficIncidentIconProvider(incident);
Drawable incidentDrawable = provider.getIcon(context, TrafficIncidentIconProvider.IconSize.LARGE);
val provider = TrafficIncidentIconProvider(incident)
val incidentDrawable = provider.getIcon(context, TrafficIncidentIconProvider.IconSize.LARGE)

image

Incidents list

image

Incidents list with clusters