HERE iOS SDK Developer's Guide

NMATrafficManager

Class Summary

class NMATrafficManager

Derived from: NSObject

Manages traffic services for the NMA SDK.

Include: NMAKit.framework/headers/NMATrafficManager.h

Inheritance Diagrams

Figure 1. Public inheritance diagram for NMATrafficManager

[For complete information, see the section Class Details]

Instance Method Summary

Table 1. Instance Methods
Instance Method Summary

-(void) addObserver:(nonnull id< NMATrafficManagerObserver >) observer

Add a NMATrafficManagerObserver.

-(void) cancelRequest:(nonnull NSNumber *) requestId

Cancel a traffic request.

-(void) getTrafficEventsOnRoute:(nonnull NMARoute *) route withCompletion:(nonnull NMATrafficCompletionBlock ) completionBlock

Retrieve the traffic events on a given route.

-(void) getTrafficEventsOnRouteElements:(nonnull NSArray< NMARouteElement * > *) routeElements withCompletion:(nonnull NMATrafficCompletionBlock ) completionBlock

Retrieve the traffic events for a given list of route elements.

-(nonnull instancetype) init

-(void) removeObserver:(nonnull id< NMATrafficManagerObserver >) observer

Remove a NMATrafficManagerObserver.

-(nullable NSNumber *) requestTrafficOnRoute:(nonnull NMARoute *) route

Request traffic information for given route.

Class Method Summary

Table 2. Class Methods
Class Methods

+(nonnull instancetype) new

+(BOOL) setRefreshInterval:(NSTimeInterval) refreshInterval

Sets the interval at which traffic data is refreshed.

+(nonnull NMATrafficManager *) sharedTrafficManager

Returns the NMATrafficManager singleton instance.

Class Details

Manages traffic services for the NMA SDK.

This is a singleton class and thus should never be retained, released, or instantiated. The singleton instance is accessed via the sharedTrafficManager method.

Instance Method Details

-(void) addObserver:(nonnull id< NMATrafficManagerObserver >) observer

Add a NMATrafficManagerObserver.

Parameters:

  • observer

    to be added

-(void) cancelRequest:(nonnull NSNumber *) requestId

Cancel a traffic request.

Parameters:

  • requestId

    id of the traffic request.

-(void) getTrafficEventsOnRoute:(nonnull NMARoute *) route withCompletion:(nonnull NMATrafficCompletionBlock ) completionBlock

Retrieve the traffic events on a given route.

This method retrieves traffic events for a route that have been previously downloaded, for example by calling requestTrafficOnRoute or displaying the traffic on a map.

The results are delivered asynchronously via an NMATrafficCompletionBlock. The block will contain a list of NMATrafficEvent objects if the request was successful, or a nil array and an NMATrafficRequestError code if the request failed.

For example:

[[ NMATrafficManager sharedTrafficManager] requestTrafficOnRoute:myRoute];

(...wait for the trafficDataDidFinish method of NMATrafficManagerObserver)

  • (void)trafficDataDidFinish { [[ NMATrafficManager sharedTrafficManager] getTrafficEventsOnRoute:myRoute withCompletion: ^(NSArray *eventList, NMATrafficRequestError error) { if (error == NMATrafficRequestErrorNone) { for ( NMATrafficEvent *event in eventList) { // do something with the traffic event } } }]; }

-(void) getTrafficEventsOnRouteElements:(nonnull NSArray< NMARouteElement * > *) routeElements withCompletion:(nonnull NMATrafficCompletionBlock ) completionBlock

Retrieve the traffic events for a given list of route elements.

The results are delivered asynchronously via an NMATrafficCompletionBlock. The block will contain a list of NMATrafficEvent objects if the request was successful, or a nil array and an NMATrafficRequestError code if the request failed.

See also:

getTrafficEventsOnRoute:withCompletion:

-(nonnull instancetype) init

Instances of this class should not be initialized directly

-(void) removeObserver:(nonnull id< NMATrafficManagerObserver >) observer

Remove a NMATrafficManagerObserver.

Parameters:

  • observer

    to be removed

-(nullable NSNumber *) requestTrafficOnRoute:(nonnull NMARoute *) route

Request traffic information for given route.

This method downloads the latest traffic information available along the specified route, so a data connection is required. Once downloaded, the traffic information can be viewed on a map or individual traffic events can be retrieved via the getTrafficEventsOnRoute:withCompletion and getTrafficEventsOnRouteElements:withCompletion methods.

This method returns nil if access to this operation is denied. Contact your HERE representative for more information.

Note:

Traffic requests may fail if too many are made in a short period of time.

Parameters:

  • route

    The route on which to query traffic events.

Returns:

requestId A request identifier if traffic is successfully requested, nil if the request fails.

Class Method Details

+(nonnull instancetype) new

Instances of this class should not be initialized directly

+(BOOL) setRefreshInterval:(NSTimeInterval) 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 sharedTrafficManager is called, before traffic is enabled on an NMAMapView and before routing with traffic is performed. If this method is called too late then NO will be returned.

Traffic refresh interval defaults to a value determined by the HERE traffic servers.

Parameters:

  • refreshInterval

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

Returns:

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

+(nonnull NMATrafficManager *) sharedTrafficManager

Returns the NMATrafficManager singleton instance.

Note:

Use this method to obtain a NMATrafficManager instance. Do not call init directly.

Returns:

shared NMATrafficManager instance