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 *) requestTrafficAtGeoCoordinates:(nonnull NMAGeoCoordinates *) coordinates

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

-(nullable NSNumber *) requestTrafficAtGeoCoordinates:(nonnull NMAGeoCoordinates *) coordinates radius:(NSUInteger) radius

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

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

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

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

Request traffic information for given route and radius around each waypoint. Using a radius greater than the default (10km) can impact performance.

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.

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 setRefreshInterval method.

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 *) requestTrafficAtGeoCoordinates:(nonnull NMAGeoCoordinates *) coordinates

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

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

Note:

This could fail if this is called too frequently.

Parameters:

  • coordinates

    used as to query traffic events.

Returns:

requestId if traffic is successfully requested, nil if it fails.

-(nullable NSNumber *) requestTrafficAtGeoCoordinates:(nonnull NMAGeoCoordinates *) coordinates radius:(NSUInteger) radius

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

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

Note:

This could fail if this is called too frequently.

Parameters:

  • coordinates

    used to query traffic events.

  • radius

    of the request (in km).

Returns:

requestId if traffic is successfully requested, nil if it fails.

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

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

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.

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

Request traffic information for given route and radius around each waypoint. Using a radius greater than the default (10km) can impact performance.

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.

  • radius

    Distance (in km) of the request radius.

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. This is typically every 60 seconds.

Note:

Refresh interval not applicable when traffic is initialized in manual mode.

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