HERE Android SDK Developer's Guide

TrafficUpdater

The class TrafficUpdater is a member of com.here.android.mpa.guidance .

Class Summary

public final class TrafficUpdater

extends java.lang.Object

Handles traffic update requests.

[For complete information, see the section Class Details]

Nested Class Summary

Table 1. Nested Classes in TrafficUpdater
Nested Classes

public static final enumeration TrafficUpdater.Error

Traffic status errors

public static abstract interface TrafficUpdater.GetEventsListener

Interface for report TrafficUpdaters events.

public static abstract interface TrafficUpdater.Listener

Interface to report traffic status changes.

public static final class TrafficUpdater.RequestInfo

Holds the error code and request id from a request for traffic.

public static final enumeration TrafficUpdater.RequestState

Traffic status enumeration

Method Summary

Table 2. Methods in TrafficUpdater
Methods

public void cancelRequest (long requestId)

Cancels a currently pending request.

public void clear ()

Clear current traffic events.

public void enableUpdate (boolean update)

Enable traffic updates.

public void getEvents (Route route, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route.

public void getEvents (RouteElement element, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route element.

public void getEvents (java.util.List <RouteElement> elements, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route elements.

public void getEvents (RouteElements elements, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given RouteElements.

public static TrafficUpdater getInstance ()

Gets the TrafficUpdater instance.

public boolean isUpdateEnabled ()

Check to see if traffic updating is enabled.

public RequestInfo request (GeoCoordinate center, Listener listener)

Request traffic with given center coordinates and the default radius (10km).

public RequestInfo request (GeoCoordinate center, int radius, Listener listener)

Request traffic with given center coordinates and radius.

public RequestInfo request (Route route, Listener listener)

Request traffic for given route with a default radius (10km) around each waypoint.

public RequestInfo request (Route route, int radius, Listener listener)

Request traffic for given route and radius around each waypoint.

public RequestInfo request (RouteElements elements, Listener listener)

Request traffic for a RouteElements object.

public boolean setRefreshInterval (int refreshInterval)

Sets the interval at which traffic data is refreshed.

Class Details

Handles traffic update requests.

Method Details

public void cancelRequest (long requestId)

Cancels a currently pending request.

Parameters:

  • requestId

    The request ID to cancel. Can be obtained from the getRequestId() returned in the original request.

public void clear ()

Clear current traffic events.

public void enableUpdate (boolean update)

Enable traffic updates.

Parameters:

  • update

    True if traffic updates requested. False otherwise.

public void getEvents (Route route, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route. It's a good idea to call request(Route, TrafficUpdater.Listener) prior to making this call.

NOTE: Truck routes and public transit timetable routes are unsupported. TrafficUpdater.GetEventsListener will return with error java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • route

    The Route to check for traffic events.

  • listener

    The listener which will receive the list of TrafficEvents.

public void getEvents (RouteElement element, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route element. It's a good idea to call request(Route, TrafficUpdater.Listener) prior to making this call.

NOTE: Truck routes and public transit timetable routes are unsupported. TrafficUpdater.GetEventsListener will return with error java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • element

    The RouteElement to check for traffic events.

  • listener

    The listener which will receive the list of TrafficEvents.

public void getEvents (java.util.List <RouteElement> elements, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given route elements. It's a good idea to call request(RouteElements, TrafficUpdater.Listener) prior to making this call.

NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.GetEventsListener will return with error java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • elements

    The list of RouteElement objects to check for traffic events.

  • listener

    The listener which will receive the list of TrafficEvents.

public void getEvents (RouteElements elements, GetEventsListener listener)

Gets a list of TrafficEvent objects that affect the given RouteElements. It's a good idea to call request(RouteElements, TrafficUpdater.Listener) prior to making this call.

NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.GetEventsListener will return with error java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • elements

    The RouteElements to check for traffic events.

  • listener

    The listener which will receive the list of TrafficEvents.

public static TrafficUpdater getInstance ()

Gets the TrafficUpdater instance.

Returns:

The TrafficUpdater instance.

public boolean isUpdateEnabled ()

Check to see if traffic updating is enabled. If it is not, no calls to any request traffic functions will have any effect.

Returns:

true if traffic updating is enabled. false otherwise.

public RequestInfo request (GeoCoordinate center, Listener listener)

Request traffic with given center coordinates and the default radius (10km).

Parameters:

  • center

    Center coordinate where traffic updates are requested.

  • listener

    Listener that will notified when request completes.

Returns:

A TrafficUpdater.RequestInfo containing the error code of the request and a request id if the error is java.lang.Error#NONE.

public RequestInfo request (GeoCoordinate center, int radius, Listener listener)

Request traffic with given center coordinates and radius. Using a radius greater than the default (10km) can impact performance.

Parameters:

  • center

    Center coordinate where traffic updates are requested.

  • radius

    Distance (in km) of the request radius.

  • listener

    Listener that will notified when request completes.

Returns:

A TrafficUpdater.RequestInfo containing the error code of the request and a request id if the error is java.lang.Error#NONE.

public RequestInfo request (Route route, Listener listener)

Request traffic for given route with a default radius (10km) around each waypoint.

NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.RequestInfo will return java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • route

    Route used to query traffic events.

  • listener

    Listener that will notified when request completes.

Returns:

A TrafficUpdater.RequestInfo containing the error code of the request and a request id if the error is java.lang.Error#NONE.

public RequestInfo request (Route route, int radius, Listener listener)

Request traffic for given route and radius around each waypoint.

NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.RequestInfo will return java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • route

    Route used to query traffic events.

  • radius

    Distance (in km) of the request radius.

  • listener

    Listener that will notified when request completes.

Returns:

A TrafficUpdater.RequestInfo containing the error code of the request and a request id if the error is java.lang.Error#NONE.

public RequestInfo request (RouteElements elements, Listener listener)

Request traffic for a RouteElements object.

NOTE: Truck route elements and public transport timetable route elements are unsupported. TrafficUpdater.RequestInfo will return java.lang.Error#UNSUPPORTED_ROUTE_MODE.

Parameters:

  • elements

    The RouteElements object to request traffic on.

  • listener

    Listener that will notified when request completes.

Returns:

A TrafficUpdater.RequestInfo containing the error code of the request and a request id if the error is java.lang.Error#NONE.

public boolean setRefreshInterval (int refreshInterval)

Sets the interval at which traffic data is refreshed. This method MUST be called before the HERE SDK uses any traffic in the current app session - e.g. before any other TrafficUpdater methods are called, before traffic is enabled on a Map View and before routing with traffic is performed. If this method is called too late then false will be returned. Traffic refresh interval defaults to a value determined by the HERE traffic servers.

Parameters:

  • refreshInterval

    Refresh interval in seconds. Must be within the range 60..300.

Returns:

refreshInterval True the interval was set successfully, NO if traffic is already initialized or if refreshInterval is outside the valid range.