summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-07-17 14:14:47 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2018-07-20 09:46:38 -0700
commit0453ade158b5b9430d68b5752afbcca988bc46f7 (patch)
treeb148cdb55b9ecb78c29c2d89e2ad03a3c5fc7550
parent2c42e9b96bc997d842a54685bfa04f6b8921d97c (diff)
downloadqtlocation-mapboxgl-0453ade158b5b9430d68b5752afbcca988bc46f7.tar.gz
[ios] Rever the default location manager to the wrap based implementation.
-rw-r--r--platform/darwin/src/MGLLocationManager.h80
-rw-r--r--platform/darwin/src/MGLLocationManager.m102
-rw-r--r--platform/darwin/src/MGLLocationManager_Private.h3
-rw-r--r--platform/ios/src/MGLMapView.mm2
4 files changed, 166 insertions, 21 deletions
diff --git a/platform/darwin/src/MGLLocationManager.h b/platform/darwin/src/MGLLocationManager.h
index 256cf5c813..1b2b17d83b 100644
--- a/platform/darwin/src/MGLLocationManager.h
+++ b/platform/darwin/src/MGLLocationManager.h
@@ -16,6 +16,40 @@ NS_ASSUME_NONNULL_BEGIN
*/
@protocol MGLLocationManager <NSObject>
+@optional
+
+#pragma mark Determining Location Updates Accuracy
+
+/**
+ 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.
+ */
+@property(nonatomic, assign) CLLocationDistance distanceFilter;
+
+/**
+ 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.
+ */
+@property (nonatomic, assign) CLLocationAccuracy desiredAccuracy;
+
+/**
+ 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.
+ */
+@property (nonatomic, assign) CLActivityType activityType;
+
@required
/**
@@ -26,10 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, weak) id<MGLLocationManagerDelegate> delegate;
-/**
- Specifies a physical device orientation.
- */
-@property (nonatomic) CLDeviceOrientation headingOrientation;
+#pragma mark Requesting Authorization for Location Services
/**
Returns the current localization authorization status.
@@ -39,6 +70,19 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) CLAuthorizationStatus authorizationStatus;
/**
+ Requests permission to use the location services whenever the app is running.
+ */
+- (void)requestAlwaysAuthorization;
+
+/**
+ Requests permission to use the location services while the app is in
+ the foreground.
+ */
+- (void)requestWhenInUseAuthorization;
+
+#pragma mark Initiating Location Updates
+
+/**
Starts the generation of location updates that reports the user's current location.
*/
- (void)startUpdatingLocation;
@@ -48,26 +92,22 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)stopUpdatingLocation;
-/**
- Starts the generation of heading updates that reports the user's current hading.
- */
-- (void)startUpdatingHeading;
+#pragma mark Initiating Heading Updates
/**
- Stops the generation of heading updates.
+ Specifies a physical device orientation.
*/
-- (void)stopUpdatingHeading;
+@property (nonatomic) CLDeviceOrientation headingOrientation;
/**
- Requests permission to use the location services whenever the app is running.
+ Starts the generation of heading updates that reports the user's current hading.
*/
-- (void)requestAlwaysAuthorization;
+- (void)startUpdatingHeading;
/**
- Requests permission to use the location services while the app is in
- the foreground.
+ Stops the generation of heading updates.
*/
-- (void)requestWhenInUseAuthorization;
+- (void)stopUpdatingHeading;
/**
Dissmisses immediately the heading calibration view from screen.
@@ -77,11 +117,13 @@ NS_ASSUME_NONNULL_BEGIN
@end
/**
- The `MGLLocationManagerDelegate` protocol defines a set of methods that you
- use to receive location updates from the associated location manager.
+ The `MGLLocationManagerDelegate` protocol defines a set of methods that `MGLMapView`
+ uses to receive location updates from the associated location manager.
*/
@protocol MGLLocationManagerDelegate <NSObject>
+#pragma mark Responding to Location Updates
+
/**
Notifies the delegate with the new location data.
@@ -94,6 +136,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)locationManager:(id<MGLLocationManager>)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations;
+#pragma mark Responding to Heading Updates
+
/**
Notifies the delegate with the new heading data.
@@ -110,6 +154,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(id<MGLLocationManager>)manager;
+#pragma mark Responding to Location Updates Errors
+
/**
Notifies the delegate that the location manager was unable to retrieve
location updates.
diff --git a/platform/darwin/src/MGLLocationManager.m b/platform/darwin/src/MGLLocationManager.m
index 4349de2f36..7b65324b62 100644
--- a/platform/darwin/src/MGLLocationManager.m
+++ b/platform/darwin/src/MGLLocationManager.m
@@ -1,10 +1,108 @@
#import "MGLLocationManager_Private.h"
-@implementation CLLocationManager (MGLAdditions)
+@interface MGLCLLocationManager()<CLLocationManagerDelegate>
-- (CLAuthorizationStatus)authorizationStatus
+@property (nonatomic) CLLocationManager *locationManager;
+
+@end
+
+@implementation MGLCLLocationManager
+
+- (instancetype)init
+{
+ if (self = [super init]) {
+ _locationManager = [[CLLocationManager alloc] init];
+ _locationManager.delegate = self;
+ }
+ return self;
+}
+
+@synthesize delegate;
+
+- (void)setHeadingOrientation:(CLDeviceOrientation)headingOrientation
+{
+ self.locationManager.headingOrientation = headingOrientation;
+}
+
+- (CLDeviceOrientation)headingOrientation
{
+ return self.locationManager.headingOrientation;
+}
+
+- (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy {
+ self.locationManager.desiredAccuracy = desiredAccuracy;
+}
+
+- (CLLocationAccuracy)desiredAccuracy {
+ return self.locationManager.desiredAccuracy;
+}
+
+- (CLAuthorizationStatus)authorizationStatus {
return [CLLocationManager authorizationStatus];
}
+- (void)setActivityType:(CLActivityType)activityType {
+ self.locationManager.activityType = activityType;
+}
+
+- (CLActivityType)activityType {
+ return self.locationManager.activityType;
+}
+
+- (void)dismissHeadingCalibrationDisplay {
+ [self.locationManager dismissHeadingCalibrationDisplay];
+}
+
+- (void)requestAlwaysAuthorization {
+ [self.locationManager requestAlwaysAuthorization];
+}
+
+- (void)requestWhenInUseAuthorization {
+ [self.locationManager requestWhenInUseAuthorization];
+}
+
+- (void)startUpdatingHeading {
+ [self.locationManager startUpdatingHeading];
+}
+
+- (void)startUpdatingLocation {
+ [self.locationManager startUpdatingLocation];
+}
+
+- (void)stopUpdatingHeading {
+ [self.locationManager stopUpdatingHeading];
+}
+
+- (void)stopUpdatingLocation {
+ [self.locationManager stopUpdatingLocation];
+}
+
+- (void)dealloc
+{
+ [self.locationManager stopUpdatingLocation];
+ [self.locationManager stopUpdatingHeading];
+ self.delegate = nil;
+}
+
+#pragma mark - CLLocationManagerDelegate
+
+- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
+ if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateLocations:)]) {
+ [self.delegate locationManager:self didUpdateLocations:locations];
+ }
+}
+
+- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
+ if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateHeading:)]) {
+ [self.delegate locationManager:self didUpdateHeading:newHeading];
+ }
+}
+
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager {
+ if ([self.delegate respondsToSelector:@selector(locationManagerShouldDisplayHeadingCalibration:)]) {
+ return [self.delegate locationManagerShouldDisplayHeadingCalibration:self];
+ }
+
+ return NO;
+}
@end
diff --git a/platform/darwin/src/MGLLocationManager_Private.h b/platform/darwin/src/MGLLocationManager_Private.h
index da1ab9bfb2..4f09405e71 100644
--- a/platform/darwin/src/MGLLocationManager_Private.h
+++ b/platform/darwin/src/MGLLocationManager_Private.h
@@ -1,4 +1,5 @@
#import "MGLLocationManager.h"
-@interface CLLocationManager (MGLAdditions) <MGLLocationManager>
+@interface MGLCLLocationManager : NSObject<MGLLocationManager>
+
@end
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 925e8dc5ce..81e13b54a7 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4710,7 +4710,7 @@ public:
{
// If no custom location manager is provided will use the internal implementation.
if (!self.locationManager) {
- self.locationManager = [[CLLocationManager alloc] init];
+ self.locationManager = [[MGLCLLocationManager alloc] init];
}
if (self.locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined)