summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-06-22 10:46:57 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2018-07-20 09:46:38 -0700
commit667abe170696d9acbab4d67ae89f8598ca0c0fbc (patch)
tree65dea350e856f69509464daeee5fdaa6b3369a99
parent560b52f4a7aee29a0e3bc1f2fecb9712acb55a79 (diff)
downloadqtlocation-mapboxgl-667abe170696d9acbab4d67ae89f8598ca0c0fbc.tar.gz
[ios] Add API methods to handle heading events.
-rw-r--r--platform/darwin/src/MGLLocationManager.h7
-rw-r--r--platform/darwin/src/MGLLocationManager.m14
-rw-r--r--platform/ios/src/MGLMapView.mm19
3 files changed, 33 insertions, 7 deletions
diff --git a/platform/darwin/src/MGLLocationManager.h b/platform/darwin/src/MGLLocationManager.h
index 1c9cafabd7..a2b237942c 100644
--- a/platform/darwin/src/MGLLocationManager.h
+++ b/platform/darwin/src/MGLLocationManager.h
@@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)requestAlwaysAuthorization;
- (void)requestWhenInUseAuthorization;
+- (void)dismissHeadingCalibrationDisplay;
+
@end
/**
@@ -40,6 +42,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)locationManager:(id<MGLLocationManager>)manager
didUpdateHeading:(CLHeading *)newHeading;
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(id<MGLLocationManager>)manager;
+
+- (void)locationManager:(id<MGLLocationManager>)manager
+ didFailWithError:(nonnull NSError *)error;
+
@optional
@end
diff --git a/platform/darwin/src/MGLLocationManager.m b/platform/darwin/src/MGLLocationManager.m
index ad2604d84b..eb6053591a 100644
--- a/platform/darwin/src/MGLLocationManager.m
+++ b/platform/darwin/src/MGLLocationManager.m
@@ -64,6 +64,11 @@
[self.locationManager stopUpdatingLocation];
}
+- (void)dismissHeadingCalibrationDisplay
+{
+ [self.locationManager dismissHeadingCalibrationDisplay];
+}
+
- (void)dealloc
{
[self.locationManager stopUpdatingLocation];
@@ -87,4 +92,13 @@
}
}
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager
+{
+ if ([self.delegate respondsToSelector:@selector(locationManagerShouldDisplayHeadingCalibration:)]) {
+ return [self.delegate locationManagerShouldDisplayHeadingCalibration:self];
+ }
+
+ return NO;
+}
+
@end
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 5528112161..846b01fe9d 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4973,12 +4973,12 @@ public:
}
}
-- (void)locationManager:(MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations
+- (void)locationManager:(id<MGLLocationManager>)manager didUpdateLocations:(NSArray *)locations
{
[self locationManager:manager didUpdateLocations:locations animated:YES];
}
-- (void)locationManager:(__unused MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated
+- (void)locationManager:(__unused id<MGLLocationManager>)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated
{
CLLocation *oldLocation = self.userLocation.location;
CLLocation *newLocation = locations.lastObject;
@@ -5205,16 +5205,21 @@ public:
return direction;
}
-- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(id<MGLLocationManager>)manager
{
- if (self.displayHeadingCalibration) [manager performSelector:@selector(dismissHeadingCalibrationDisplay)
- withObject:nil
+ if (self.displayHeadingCalibration) [self performSelector:@selector(dismissHeadingCalibrationDisplay:)
+ withObject:manager
afterDelay:10.0];
return self.displayHeadingCalibration;
}
-- (void)locationManager:(__unused CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
+- (void)dismissHeadingCalibrationDisplay:(id<MGLLocationManager>)manager
+{
+ [manager dismissHeadingCalibrationDisplay];
+}
+
+- (void)locationManager:(__unused id<MGLLocationManager>)manager didUpdateHeading:(CLHeading *)newHeading
{
if ( ! _showsUserLocation || self.pan.state == UIGestureRecognizerStateBegan || newHeading.headingAccuracy < 0) return;
@@ -5241,7 +5246,7 @@ public:
}
}
-- (void)locationManager:(__unused CLLocationManager *)manager didFailWithError:(NSError *)error
+- (void)locationManager:(__unused id<MGLLocationManager>)manager didFailWithError:(NSError *)error
{
if ([error code] == kCLErrorDenied)
{