public final class TrafficUpdater
extends java.lang.Object
By default, new traffic is automatically requested each time the map is moved (such as by
panning, zooming, or with map movement during navigation). If the map is not moved, new traffic
will be requested at a rate equal to the value set using the TrafficUpdater.setRefreshInterval(int)
method.
| Modifier and Type | Class and Description |
|---|---|
static class |
TrafficUpdater.Error
Traffic status errors
|
static interface |
TrafficUpdater.GetEventsListener
Interface for report TrafficUpdaters events.
|
static interface |
TrafficUpdater.Listener
Interface to report traffic status changes.
|
static class |
TrafficUpdater.RequestInfo
Holds the error code and request id from a request for traffic.
|
static class |
TrafficUpdater.RequestState
Traffic status enumeration
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancelRequest(long requestId)
Cancels a currently pending request.
|
void |
clear()
Clear current traffic events.
|
boolean |
disableAutoUpdate()
Disables automatic traffic information updates.
|
void |
enableUpdate(boolean update)
Enables or disables all traffic updates that were launched in manual mode.
|
void |
getEvents(java.util.List<RouteElement> elements,
TrafficUpdater.GetEventsListener listener)
Gets a list of
TrafficEvent objects that affect the given route elements. |
void |
getEvents(RouteElements elements,
TrafficUpdater.GetEventsListener listener)
Gets a list of
TrafficEvent objects that affect the given RouteElements. |
void |
getEvents(RouteElement element,
TrafficUpdater.GetEventsListener listener)
Gets a list of
TrafficEvent objects that affect the given route element. |
void |
getEvents(Route route,
TrafficUpdater.GetEventsListener listener)
Gets a list of
TrafficEvent objects that affect the given route. |
static TrafficUpdater |
getInstance()
Gets the
TrafficUpdater instance. |
boolean |
isAutoUpdateEnabled()
Returns a boolean indicating whether automatic traffic updates are enabled.
|
boolean |
isUpdateEnabled()
Check to see if traffic updating is enabled.
|
TrafficUpdater.RequestInfo |
request(GeoCoordinate center,
int radius,
TrafficUpdater.Listener listener)
Request traffic with given center coordinates and radius.
|
TrafficUpdater.RequestInfo |
request(GeoCoordinate center,
TrafficUpdater.Listener listener)
Request traffic with given center coordinates and the default radius (5km).
|
TrafficUpdater.RequestInfo |
request(RouteElements elements,
TrafficUpdater.Listener listener)
Request traffic for a
RouteElements object. |
TrafficUpdater.RequestInfo |
request(Route route,
int radius,
TrafficUpdater.Listener listener)
Request traffic for given route and radius around each waypoint.
|
TrafficUpdater.RequestInfo |
request(Route route,
TrafficUpdater.Listener listener)
Request traffic for given route with a default radius (5km) around each waypoint.
|
boolean |
setRefreshInterval(int refreshInterval)
Sets the interval at which traffic data is refreshed.
|
public static TrafficUpdater getInstance()
TrafficUpdater instance.TrafficUpdater instance.public boolean setRefreshInterval(int refreshInterval)
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. This is typically every 60 seconds.
NOTE: Refresh interval not applicable when traffic is initialized in manual mode, e.g. when callingTrafficUpdater.disableAutoUpdate().refreshInterval - Refresh interval in seconds. Must be within the range 60..300.public boolean disableAutoUpdate()
To implement custom traffic updates in an app, use this method to turn off automatic
updating, then call
TrafficUpdater.request(GeoCoordinate, int, TrafficUpdater.Listener)
as needed to request traffic in a radius around a given location.
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.
NOTE: Once traffic engine starts with either auto or manual, user can not change it back.public boolean isAutoUpdateEnabled()
public void clear()
public void enableUpdate(boolean update)
Map.setTrafficInfoVisible(boolean) is called. If this is set to
false, all next manual traffic requests
(e.g. TrafficUpdater.request(Route, Listener)) will be ignored.
It is also possible to cancel particular manual request using
TrafficUpdater.cancelRequest(long).
update - True if manual traffic updates are enabled. False otherwise.TrafficUpdater.request(Route, Listener),
TrafficUpdater.request(GeoCoordinate, int, Listener)public boolean isUpdateEnabled()
true if traffic updating is enabled. false otherwise.public TrafficUpdater.RequestInfo request(GeoCoordinate center, TrafficUpdater.Listener listener)
Developer must enable manual traffic updates using
TrafficUpdater.enableUpdate(boolean) before calling this method.
center - Center coordinate where traffic updates are requested.listener - Listener that will notified when request completes.TrafficUpdater.RequestInfo containing the error code of the request and a request id if
the error is TrafficUpdater.Error.NONE.TrafficUpdater.enableUpdate(boolean)public TrafficUpdater.RequestInfo request(GeoCoordinate center, int radius, TrafficUpdater.Listener listener)
Developer must enable manual traffic updates using
TrafficUpdater.enableUpdate(boolean) before calling this method.
center - Center coordinate where traffic updates are requested.radius - Distance (in km) of the request radius.listener - Listener that will notified when request completes.TrafficUpdater.RequestInfo containing the error code of the request and a request id if
the error is TrafficUpdater.Error.NONE.TrafficUpdater.enableUpdate(boolean)public TrafficUpdater.RequestInfo request(Route route, TrafficUpdater.Listener listener)
Developer must enable manual traffic updates using
TrafficUpdater.enableUpdate(boolean) before calling this method.
NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.RequestInfo
will return TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
route - Route used to query traffic events.listener - Listener that will notified when request completes.TrafficUpdater.RequestInfo containing the error code of the request and a request id if
the error is TrafficUpdater.Error.NONE.TrafficUpdater.enableUpdate(boolean)public TrafficUpdater.RequestInfo request(Route route, int radius, TrafficUpdater.Listener listener)
Developer must enable manual traffic updates using
TrafficUpdater.enableUpdate(boolean) before calling this method.
NOTE: Truck routes and public transport timetable routes are unsupported. TrafficUpdater.RequestInfo
will return TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
route - Route used to query traffic events.radius - Distance (in km) of the request radius.listener - Listener that will notified when request completes.TrafficUpdater.RequestInfo containing the error code of the request and a request id if
the error is TrafficUpdater.Error.NONE.TrafficUpdater.enableUpdate(boolean)public TrafficUpdater.RequestInfo request(RouteElements elements, TrafficUpdater.Listener listener)
RouteElements object.
Developer must enable manual traffic updates using
TrafficUpdater.enableUpdate(boolean) before calling this method.
NOTE: Truck route elements and public transport timetable route elements are unsupported.
TrafficUpdater.RequestInfo will return TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
elements - The RouteElements object to request traffic on.listener - Listener that will notified when request completes.TrafficUpdater.RequestInfo containing the error code of the request and a request id if
the error is TrafficUpdater.Error.NONE.TrafficUpdater.enableUpdate(boolean)public void cancelRequest(long requestId)
requestId - The request ID to cancel. Can be obtained from the
TrafficUpdater.RequestInfo.getRequestId() returned in the original request.public void getEvents(Route route, TrafficUpdater.GetEventsListener listener)
TrafficEvent objects that affect the given route. It's a good idea to
call TrafficUpdater.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
TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
route - The Route to check for traffic events.listener - The listener which will receive the list of TrafficEvents.public void getEvents(RouteElement element, TrafficUpdater.GetEventsListener listener)
TrafficEvent objects that affect the given route element. It's a good
idea to call TrafficUpdater.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
TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
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, TrafficUpdater.GetEventsListener listener)
TrafficEvent objects that affect the given route elements. It's a good
idea to call TrafficUpdater.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
TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
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, TrafficUpdater.GetEventsListener listener)
TrafficEvent objects that affect the given RouteElements. It's
a good idea to call TrafficUpdater.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
TrafficUpdater.Error.UNSUPPORTED_ROUTE_MODE.
elements - The RouteElements to check for traffic events.listener - The listener which will receive the list of TrafficEvents.