PassiveLocationManager
open class PassiveLocationManager : NSObject
extension PassiveLocationManager: PassiveNavigationEventsManagerDataSource
extension PassiveLocationManager: HistoryRecording
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.
-
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 idealized user location. Snapped to the road network, if applicable, otherwise raw.
See also
rawLocationDeclaration
Swift
public var location: CLLocation? { get }
-
The most recently received user location.
Note
This is a raw location received fromsystemLocationManager
or set manually viaupdateLocation(_:completion:)
. To obtain an idealized location, use thelocation
property.Declaration
Swift
public private(set) var rawLocation: CLLocation? { get }
-
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()
-
Starts electronic horizon updates.
Pass
nil
to use the default configuration. Updates will be delivered inNotification.Name.electronicHorizonDidUpdatePosition
notification. For more info, read the Electronic Horizon Guide.Postcondition
To change electronic horizon options call this method again with new options.
Note
The Mapbox Electronic Horizon feature of the Mapbox Navigation SDK is in public beta and is subject to changes, including its pricing. Use of the feature is subject to the beta product restrictions in the Mapbox Terms of Service. Mapbox reserves the right to eliminate any free tier or free evaluation offers at any time and require customers to place an order to purchase the Mapbox Electronic Horizon feature, regardless of the level of use of the feature.
Declaration
Swift
public func startUpdatingElectronicHorizon(with options: ElectronicHorizonOptions? = nil)
Parameters
options
Options which will be used to configure electronic horizon updates.
-
Stops electronic horizon updates.
Declaration
Swift
public func stopUpdatingElectronicHorizon()
-
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, datasetProfileIdentifier: ProfileIdentifier? = 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.datasetProfileIdentifier
custom profile setting, used for selecting tiles type for navigation. If set to
nil
- will not modify current profile setting.
-
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 }
-
Keys in the user info dictionaries of various notifications posted by instances of
See morePassiveLocationManager
.Declaration
Swift
public struct NotificationUserInfoKey : Hashable, Equatable, RawRepresentable