PassiveLocationManager
open class PassiveLocationManager : NSObject
extension PassiveLocationManager: PassiveNavigationEventsManagerDataSource
extension PassiveLocationManager: CLLocationManagerDelegate
An object that notifies its delegate when the user’s location changes, minimizing the noise that normally accompanies location updates from a CLLocationManager
object.
Unlike Router
classes such as RouteController
and LegacyRouteController
, this class operates without a predefined route, matching the user’s location to the road network at large. You can use a passive location manager to determine a starting point for a route that you calculate using the Directions.calculate(_:completionHandler:)
method. If the user happens to be moving while you calculate the route, the passive location manager makes it less likely that the route will begin with a short segment on a side road or driveway and a confusing instruction to turn onto the current road.
To find out when the user’s location changes, implement the PassiveLocationManagerDelegate
protocol, or observe Notification.Name.passiveLocationManagerDidUpdate
notifications for more detailed information.
Important
Creating an instance of this class will start a free-driving session. If the application goes into the background or you temporarily stop needing location updates for any other reason, temporarily pause the trip session using thePassiveLocationManager.pauseTripSession()
method to avoid unnecessary costs. The trip session also stops when the instance is deinitialized. For more information, see the “Pricing” guide.
-
Initializes the location manager with the given directions service.
Postcondition
Call
startUpdatingLocation()
afterwards to begin receiving location updates.Declaration
Swift
public required init(directions: Directions = NavigationSettings.shared.directions, systemLocationManager: NavigationLocationManager? = nil, eventsManagerType: NavigationEventsManager.Type? = nil, userInfo: [String: String?]? = nil)
Parameters
directions
The directions service that allows the location manager to access road network data. If this argument is omitted, the shared value of
NavigationSettings.directions
will be used.systemLocationManager
The system location manager that provides raw locations for the receiver to match against the road network.
eventsManagerType
An optional events manager type to use.
userInfo
An optional metadata to be provided as initial value of
NavigationEventsManager.userInfo
property. -
The directions service that allows the location manager to access road network data.
Declaration
Swift
public let directions: Directions
-
A
NavigationLocationManager
that provides raw locations for the receiver to match against the road network.Declaration
Swift
public let systemLocationManager: NavigationLocationManager
-
The events manager, responsible for all telemetry.
Declaration
Swift
public var eventsManager: NavigationEventsManager { get }
-
A
TileStore
instance used by navigatorDeclaration
Swift
open var navigatorTileStore: TileStore { get }
-
The location manager’s delegate.
Declaration
Swift
public weak var delegate: PassiveLocationManagerDelegate?
-
Starts the generation of location updates.
Declaration
Swift
public func startUpdatingLocation()
-
A closure, which is called to report a result whether location update succeeded or not.
Declaration
Swift
public typealias UpdateLocationCompletionHandler = (_ result: Result<CLLocation, Error>) -> Void
Parameters
result
Result, which in case of success contains location (which was updated), and error, in case of failure.
-
Manually sets the current location.
This method stops any automatic location updates.
Declaration
Swift
public func updateLocation(_ location: CLLocation?, completion: UpdateLocationCompletionHandler? = nil)
Parameters
location
Location, which will be used by navigator.
completion
Completion handler, which will be called when asynchronous operation completes.
-
Pauses the Free Drive session.
Use this method to extend the existing Free Drive session if you temporarily don’t need navigation updates. For more info, read the Pricing Guide.
Declaration
Swift
public func pauseTripSession()
-
Resumes the Free Drive session.
Resumes navigation updates paused by
PassiveLocationManager.pauseTripSession()
. For more info, read the Pricing Guide.Declaration
Swift
public func resumeTripSession()
-
A custom configuration for electronic horizon observations.
Set this property to
nil
to use the default configuration.Declaration
Swift
public var electronicHorizonOptions: ElectronicHorizonOptions? { get set }
-
The road graph that is updated as the passive location manager tracks the user’s location.
Declaration
Swift
public var roadGraph: RoadGraph { get }
-
The road object store that is updated as the passive location manager tracks the user’s location.
Declaration
Swift
public var roadObjectStore: RoadObjectStore { get }
-
The road object matcher that allows to match user-defined road objects.
Declaration
Swift
public var roadObjectMatcher: RoadObjectMatcher { get }
-
Path to the directory where history could be stored when
PassiveLocationManager.writeHistory(completionHandler:)
is called.Declaration
Swift
public static var historyDirectoryURL: URL? { get set }
-
Starts recording history for debugging purposes.
Postcondition
Use thestopRecordingHistory(writingFileWith:)
method to stop recording history and write the recorded history to a file.Declaration
Swift
public static func startRecordingHistory()
-
A closure to be called when history writing ends.
Declaration
Swift
public typealias HistoryFileWritingCompletionHandler = (_ historyFileURL: URL?) -> Void
Parameters
historyFileURL
A URL to the file that contains history data. This argument is
nil
if no history data has been written because history recording has not yet begun. Use thestartRecordingHistory()
method to begin recording before attempting to write a history file. -
Stops recording history, asynchronously writing any recorded history to a file.
Upon completion, the completion handler is called with the URL to a file in the directory specified by
PassiveLocationManager.historyDirectoryURL
. The file contains details about the passive location manager’s activity that may be useful to include when reporting an issue to Mapbox.Precondition
Use thestartRecordingHistory()
method to begin recording history. If thestartRecordingHistory()
method has not been called, this method has no effect.Postcondition
To write history incrementally without an interruption in history recording, use the
startRecordingHistory()
method immediately after this method. If you use thestartRecordingHistory()
method inside the completion handler of this method, history recording will be paused while the file is being prepared.Declaration
Swift
public static func stopRecordingHistory(writingFileWith completionHandler: @escaping HistoryFileWritingCompletionHandler)
Parameters
completionHandler
A closure to be executed when the history file is ready.
-
Keys in the user info dictionaries of various notifications posted by instances of
See morePassiveLocationManager
.Declaration
Swift
public struct NotificationUserInfoKey : Hashable, Equatable, RawRepresentable