MGLLocationManager
@protocol MGLLocationManager <NSObject>
The MGLLocationManager
protocol defines a set of methods that a class must implement in order to serve as the location manager of an MGLMapView
. A location manager is responsible for notifying the map view about location-related events, such as a change in the user’s location. This protocol is similar to the Core Location framework’s CLLocationManager
class, but your implementation does not need to be based on CLLocationManager
.
To receive location updates from an object that conforms to the MGLLocationManager
protocol, use the optional methods available in the MGLLocationManagerDelegate
protocol.
Configuring Location Update Precision
-distanceFilter
Specifies the minimum distance (measured in meters) a device must move horizontally before a location update is generated.
The default value of this property is kCLDistanceFilterNone
when MGLMapView
uses its default location manager.
See
CLLocationManager.distanceFilter
Declaration
Objective-C
- (CLLocationDistance)distanceFilter;
Swift
optional func distanceFilter() -> CLLocationDistance
-setDistanceFilter:
Sets the minimum update distance in meters.
Declaration
Objective-C
- (void)setDistanceFilter:(CLLocationDistance)distanceFilter;
Swift
optional func setDistanceFilter(_ distanceFilter: CLLocationDistance)
Parameters
distanceFilter
The distance filter in meters.
-desiredAccuracy
Specifies the accuracy of the location data.
The default value is kCLLocationAccuracyBest
when MGLMapView
uses its default location manager.
Note
Determining a location with greater accuracy requires more time and more power.
See
CLLocationManager.desiredAccuracy
Declaration
Objective-C
- (CLLocationAccuracy)desiredAccuracy;
Swift
optional func desiredAccuracy() -> CLLocationAccuracy
-setDesiredAccuracy:
Sets the desired location accuracy.
Declaration
Objective-C
- (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy;
Swift
optional func setDesiredAccuracy(_ desiredAccuracy: CLLocationAccuracy)
Parameters
desiredAccuracy
The desired location accuracy.
-accuracyAuthorization
Specifies the level of location accuracy the Maps SDK has permission to use.
Note
If the value of this property is CLAccuracyAuthorizationFullAccuracy
, you can set the MGLLocationManager.desiredAccuracy
property to any value. If the value is CLAccuracyAuthorizationReducedAccuracy
, setting MGLLocationManager.desiredAccuracy
to a value other thankCLLocationAccuracyReduced
has no effect on the location information.
Declaration
Objective-C
- (CLAccuracyAuthorization)accuracyAuthorization;
Swift
optional func accuracyAuthorization() -> CLAccuracyAuthorization
-activityType
Specifies the type of user activity associated with the location updates.
The location manager uses this property as a cue to determine when location updates may be automatically paused.
The default value is CLActivityTypeOther
when MGLMapView
uses its default location manager.
See
CLLocationManager.activityType
Declaration
Objective-C
- (CLActivityType)activityType;
Swift
optional func activityType() -> CLActivityType
-setActivityType:
Sets the type of user activity associated with the location updates.
Declaration
Objective-C
- (void)setActivityType:(CLActivityType)activityType;
Swift
optional func setActivityType(_ activityType: CLActivityType)
Parameters
activityType
The location’s manager activity type.
-requestTemporaryFullAccuracyAuthorizationWithPurposeKey:
Requests the user’s permission to temporarily use location update services with full accuracy.
Note
If the user turned off location accuracy you may use this method to request full accuracy for a session.
Declaration
Objective-C
- (void)requestTemporaryFullAccuracyAuthorizationWithPurposeKey:
(nonnull NSString *)purposeKey;
Swift
optional func requestTemporaryFullAccuracyAuthorization(withPurposeKey purposeKey: String)
delegate
The delegate to receive location updates.
Do not set the location manager’s delegate yourself. MGLMapView
sets this property after the location manager becomes MGLMapView
’s location manager.
Declaration
Objective-C
@required
@property (nonatomic, weak, readwrite)
id<MGLLocationManagerDelegate> _Nullable delegate;
Swift
weak var delegate: MGLLocationManagerDelegate? { get set }
Requesting Authorization for Location Services
authorizationStatus
Returns the current localization authorization status.
See
+[CLLocationManger authorizationStatus]
Declaration
Objective-C
@required
@property (nonatomic, readonly) CLAuthorizationStatus authorizationStatus;
Swift
var authorizationStatus: CLAuthorizationStatus { get }
-requestAlwaysAuthorization
Requests permission to use the location services whenever the app is running.
Declaration
Objective-C
- (void)requestAlwaysAuthorization;
Swift
func requestAlwaysAuthorization()
-requestWhenInUseAuthorization
Requests permission to use the location services while the app is in the foreground.
Declaration
Objective-C
- (void)requestWhenInUseAuthorization;
Swift
func requestWhenInUseAuthorization()
Initiating Location Updates
-startUpdatingLocation
Starts the generation of location updates that reports the user’s current location.
Declaration
Objective-C
- (void)startUpdatingLocation;
Swift
func startUpdatingLocation()
-stopUpdatingLocation
Stops the generation of location updates.
Declaration
Objective-C
- (void)stopUpdatingLocation;
Swift
func stopUpdatingLocation()
Initiating Heading Updates
headingOrientation
Specifies a physical device orientation.
Declaration
Objective-C
@required
@property (nonatomic, assign, unsafe_unretained, readwrite)
CLDeviceOrientation headingOrientation;
Swift
var headingOrientation: CLDeviceOrientation { get set }
-startUpdatingHeading
Starts the generation of heading updates that reports the user’s current hading.
Declaration
Objective-C
- (void)startUpdatingHeading;
Swift
func startUpdatingHeading()
-stopUpdatingHeading
Stops the generation of heading updates.
Declaration
Objective-C
- (void)stopUpdatingHeading;
Swift
func stopUpdatingHeading()
-dismissHeadingCalibrationDisplay
Dissmisses immediately the heading calibration view from screen.
Declaration
Objective-C
- (void)dismissHeadingCalibrationDisplay;
Swift
func dismissHeadingCalibrationDisplay()
iOS SDK
Examples
SDK JS Reference
- Annotations
- Appendices
- NSExpression(MGLAdditions)
- NSValue(MGLAdditions)
- NSValue(MGLCircleStyleLayerAdditions)
- NSValue(MGLFillExtrusionStyleLayerAdditions)
- NSValue(MGLFillStyleLayerAdditions)
- NSValue(MGLHillshadeStyleLayerAdditions)
- NSValue(MGLLineStyleLayerAdditions)
- NSValue(MGLRasterStyleLayerAdditions)
- NSValue(MGLSymbolStyleLayerAdditions)
- MGLAccountManager
- MGLAnnotationImage
- MGLAnnotationView
- MGLAttributedExpression
- MGLAttributionInfo
- MGLBackgroundStyleLayer
- MGLCircleStyleLayer
- MGLClockDirectionFormatter
- MGLCompassButton
- MGLCompassDirectionFormatter
- MGLComputedShapeSource
- MGLCoordinateFormatter
- MGLDistanceFormatter
- MGLFillExtrusionStyleLayer
- MGLFillStyleLayer
- MGLForegroundStyleLayer
- MGLHeatmapStyleLayer
- MGLHillshadeStyleLayer
- MGLImageSource
- MGLLight
- MGLLineStyleLayer
- MGLLoggingConfiguration
- MGLMapCamera
- MGLMapSnapshot
- MGLMapSnapshotOptions
- MGLMapSnapshotOverlay
- MGLMapSnapshotter
- MGLMapView
- MGLMultiPoint
- MGLMultiPolygon
- MGLMultiPolyline
- MGLNetworkConfiguration
- MGLOfflinePack
- MGLOfflineStorage
- MGLPointAnnotation
- MGLPointCollection
- MGLPolygon
- MGLPolyline
- MGLRasterStyleLayer
- MGLRasterTileSource
- MGLShape
- MGLShapeCollection
- MGLShapeOfflineRegion
- MGLShapeSource
- MGLSource
- MGLStyle
- MGLStyleLayer
- MGLSymbolStyleLayer
- MGLTilePyramidOfflineRegion
- MGLTileSource
- MGLUserLocation
- MGLUserLocationAnnotationView
- MGLUserLocationAnnotationViewStyle
- MGLVectorStyleLayer
- MGLVectorTileSource
- MGLAnnotationVerticalAlignment
- MGLAnnotationViewDragState
- MGLAttributionInfoStyle
- MGLCirclePitchAlignment
- MGLCircleScaleAlignment
- MGLCircleTranslationAnchor
- MGLDEMEncoding
- MGLErrorCode
- MGLFillExtrusionTranslationAnchor
- MGLFillTranslationAnchor
- MGLHillshadeIlluminationAnchor
- MGLIconAnchor
- MGLIconPitchAlignment
- MGLIconRotationAlignment
- MGLIconTextFit
- MGLIconTranslationAnchor
- MGLLightAnchor
- MGLLineCap
- MGLLineJoin
- MGLLineTranslationAnchor
- MGLLoggingLevel
- MGLMapDebugMaskOptions
- MGLOfflinePackState
- MGLOrnamentPosition
- MGLOrnamentVisibility
- MGLRasterResamplingMode
- MGLResourceKind
- MGLSymbolPlacement
- MGLSymbolZOrder
- MGLTextAnchor
- MGLTextJustification
- MGLTextPitchAlignment
- MGLTextRotationAlignment
- MGLTextTransform
- MGLTextTranslationAnchor
- MGLTextWritingMode
- MGLTileCoordinateSystem
- MGLUserTrackingMode
- Formatters
- Geometry
- Location Updates
- Maps
- Offline Maps
- Other Categories
- Other Classes
- Other Constants
- Other Enumerations
- Other Functions
- Other Protocols
- Other Structures
- Other Type Definitions
- Primitive Shapes
- MGLAnnotation
- MGLCalloutView
- MGLCalloutViewDelegate
- MGLCluster
- MGLComputedShapeSourceDataSource
- MGLFeature
- MGLLocationManager
- MGLLocationManagerDelegate
- MGLMapSnapshotterDelegate
- MGLMapViewDelegate
- MGLOfflineRegion
- MGLOfflineStorageDelegate
- MGLOverlay
- MGLStylable
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- Style Content
- Style Layers
- Style Primitives
- Styling the Map
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- User Interaction
- Customizing Fonts
- Information for Style Authors
- Gesture Recognizers
- Info.plist Keys
- Migrating to Expressions
- Predicates and expressions
- Tile URL Templates
- Working with GeoJSON Data