Sorry, you need to enable JavaScript to visit this website.

Traffic examples

Traffic examples

Have a look at our functional examples to see how easy it is to implement search features with the Maps SDK.
Speed up development by using our sample code snippets in your app. Try all of this out with the Maps SDK Examples app!

Traffic incident list

Give your users information about traffic incidents around 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 the overview of which streets might be blocked or congested due to accidents,
road works or possible rain, ice, flooding, etc.

Use the code snippet below to try this in your app.

IncidentDetailsQuery query = IncidentDetailsQueryBuilder.create(IncidentStyle.S1, LONDON_BOUNDING_BOX, DEFAULT_ZOOM_LEVEL_FOR_EXAMPLE, "-1")
        .withExpandCluster(true).build();
trafficApi.findIncidentDetails(query, incidentDetailsResultListener);

 

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

private IncidentDetailsResultListener incidentDetailsResultListener = new IncidentDetailsResultListener() {
    @Override
    public void onTrafficIncidentDetailsResult(IncidentDetailsResponse result) {

        final List<TrafficIncidentItem> items = new ArrayList<>();

        TrafficIncidentVisitor visitor = new TrafficIncidentVisitor() {
            @Override
            public void visit(TrafficIncidentCluster cluster) {
                proceedWithCluster(cluster, items);
            }

            @Override
            public void visit(TrafficIncident incident) {
                proceedWithIncident(incident, items);
            }
        };

        for (BaseTrafficIncident incident : result.getIncidents()) {
            incident.accept(visitor);
        }

        view.updateTrafficIncidentsList(items);
    }

    @Override
    public void onTrafficIncidentDetailsError(Throwable error) {
        Toast.makeText(view.getContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
    }
};

 

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);

 



image

Incidents list

image

Incidents list with clusters