AI-generated Key Takeaways
-
GMSRoadSnappedLocationProviderdelivers road-snapped location updates, similar toCLLocationManagerbut optimized for driving scenarios. -
Developers can add and remove listeners to receive location updates using
addListener:andremoveListener:. -
Location updates are managed by
startUpdatingLocationandstopUpdatingLocation, enabling and disabling the delivery of location events. -
The
allowsBackgroundLocationUpdatesproperty controls whether updates continue when the app is in the background.
GMSRoadSnappedLocationProvider
@interface GMSRoadSnappedLocationProvider : NSObjectProvides updates of the device’s location. This class functions similarly to CLLocationManager, except that if the device is in driving mode, the location updates is snapped to the nearest road.
This class is not intended for subclassing.
-
Unavailable
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
Adds a listener. The listener is held with a weak reference.
Declaration
Swift
func add(_ listener: any GMSRoadSnappedLocationProviderListener)Objective-C
- (void)addListener: (nonnull id<GMSRoadSnappedLocationProviderListener>)listener;Parameters
listenerAn object conforming to the
GMSRoadSnappedLocationProviderListenerprotocol. -
Removes a listener.
Declaration
Swift
func remove(_ listener: any GMSRoadSnappedLocationProviderListener) -> BoolObjective-C
- (BOOL)removeListener: (nonnull id<GMSRoadSnappedLocationProviderListener>)listener;Parameters
listenerAn object conforming to the
GMSRoadSnappedLocationProviderListenerprotocol.Return Value
Returns YES if the listener was removed. Returns NO if the object was not a listener.
-
Starts updating the device’s road-snapped location. After this is called, the delegate will start receiving location update events.
In order to avoid battery drain or unintended logging of device location,
-stopUpdatingLocationshould be called when road-snapped location is no longer required.Declaration
Swift
func startUpdatingLocation()Objective-C
- (void)startUpdatingLocation; -
Stops updating the device’s road-snapped location. In order to avoid battery drain or unintended logging of device location, this method should be called when the listener is no longer required.
Declaration
Swift
func stopUpdatingLocation()Objective-C
- (void)stopUpdatingLocation; -
Whether the delegate should still receive location updates when the app is in the background. Defaults to NO.
Declaration
Swift
var allowsBackgroundLocationUpdates: Bool { get set }Objective-C
@property (nonatomic) BOOL allowsBackgroundLocationUpdates;