summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-05-25 15:11:25 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-07-20 09:46:38 -0700
commit357c777664ecc4fa7cddab8a4f835533354f02de (patch)
tree2c81dd31f7b84f33f195591299678a3b9a88d28f
parent6d7072162b764c2432c010cd463a5a2c0093d606 (diff)
downloadqtlocation-mapboxgl-357c777664ecc4fa7cddab8a4f835533354f02de.tar.gz
[ios] Add MGLLocationManager and MGLLocationManagerDelegate to Mapbox's maps SDK.
-rw-r--r--platform/darwin/src/MGLLocationManager.h47
-rw-r--r--platform/darwin/src/MGLLocationManager.m83
-rw-r--r--platform/darwin/src/MGLLocationManager_Private.h6
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj18
-rw-r--r--platform/ios/src/Mapbox.h1
5 files changed, 155 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLLocationManager.h b/platform/darwin/src/MGLLocationManager.h
new file mode 100644
index 0000000000..1c9cafabd7
--- /dev/null
+++ b/platform/darwin/src/MGLLocationManager.h
@@ -0,0 +1,47 @@
+#import <Foundation/Foundation.h>
+#import <CoreLocation/CoreLocation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@protocol MGLLocationManagerDelegate;
+
+/**
+ The `MGLLocationManager` protocol defines a set of methods that you
+ use to receive location-related events.
+ */
+@protocol MGLLocationManager <NSObject>
+
+@required
+
+@property (nonatomic, weak) id<MGLLocationManagerDelegate> delegate;
+@property (nonatomic) CLDeviceOrientation headingOrientation;
+@property (nonatomic, readonly) CLAuthorizationStatus authorizationStatus;
+
+- (void)startUpdatingLocation;
+- (void)startUpdatingHeading;
+
+- (void)stopUpdatingLocation;
+- (void)stopUpdatingHeading;
+
+- (void)requestAlwaysAuthorization;
+- (void)requestWhenInUseAuthorization;
+
+@end
+
+/**
+ The `MGLLocationManagerDelegate` protocol defines a set of methods that you
+ use to receive location updates from the associated location manager.
+ */
+@protocol MGLLocationManagerDelegate <NSObject>
+
+- (void)locationManager:(id<MGLLocationManager>)manager
+ didUpdateLocations:(NSArray<CLLocation *> *)locations;
+
+- (void)locationManager:(id<MGLLocationManager>)manager
+ didUpdateHeading:(CLHeading *)newHeading;
+
+@optional
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLLocationManager.m b/platform/darwin/src/MGLLocationManager.m
new file mode 100644
index 0000000000..01f8ac32af
--- /dev/null
+++ b/platform/darwin/src/MGLLocationManager.m
@@ -0,0 +1,83 @@
+#import "MGLLocationManager_Private.h"
+
+@interface MGLCLLocationManager()<CLLocationManagerDelegate>
+
+@property (nonatomic) CLLocationManager *locationManager;
+
+@end
+
+@implementation MGLCLLocationManager
+
+@synthesize delegate;
+
+- (instancetype)init
+{
+ if (self = [super init]) {
+ _locationManager = [[CLLocationManager alloc] init];
+ _locationManager.delegate = self;
+ }
+ return self;
+}
+
+- (CLAuthorizationStatus)authorizationStatus
+{
+ return [CLLocationManager authorizationStatus];
+}
+
+- (void)setHeadingOrientation:(CLDeviceOrientation)headingOrientation
+{
+ _locationManager.headingOrientation = headingOrientation;
+}
+
+- (CLDeviceOrientation)headingOrientation
+{
+ return _locationManager.headingOrientation;
+}
+
+- (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];
+}
+
+#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];
+ }
+}
+
+@end
diff --git a/platform/darwin/src/MGLLocationManager_Private.h b/platform/darwin/src/MGLLocationManager_Private.h
new file mode 100644
index 0000000000..3d1570f0ce
--- /dev/null
+++ b/platform/darwin/src/MGLLocationManager_Private.h
@@ -0,0 +1,6 @@
+#import "MGLLocationManager.h"
+
+
+@interface MGLCLLocationManager : NSObject<MGLLocationManager>
+
+@end
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 41b6881dbe..73c959ab38 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -38,6 +38,12 @@
1F95931D1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */; };
1FC4817D2098CBC0000D09B4 /* NSPredicate+MGLPrivateAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FC4817B2098CBC0000D09B4 /* NSPredicate+MGLPrivateAdditions.h */; };
1FC4817F2098CD80000D09B4 /* NSPredicate+MGLPrivateAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FC4817B2098CBC0000D09B4 /* NSPredicate+MGLPrivateAdditions.h */; };
+ 1FCAE2A220B872A400C577DD /* MGLLocationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCAE2A020B872A400C577DD /* MGLLocationManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 1FCAE2A320B872A400C577DD /* MGLLocationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCAE2A020B872A400C577DD /* MGLLocationManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 1FCAE2A420B872A400C577DD /* MGLLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FCAE2A120B872A400C577DD /* MGLLocationManager.m */; };
+ 1FCAE2A520B872A400C577DD /* MGLLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FCAE2A120B872A400C577DD /* MGLLocationManager.m */; };
+ 1FCAE2A820B88B3800C577DD /* MGLLocationManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCAE2A620B88B3800C577DD /* MGLLocationManager_Private.h */; };
+ 1FCAE2A920B88B3800C577DD /* MGLLocationManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCAE2A620B88B3800C577DD /* MGLLocationManager_Private.h */; };
30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; };
@@ -756,6 +762,9 @@
1F7454A61ED08AB400021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLLightTest.mm; path = ../../darwin/test/MGLLightTest.mm; sourceTree = "<group>"; };
1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = "<group>"; };
1FC4817B2098CBC0000D09B4 /* NSPredicate+MGLPrivateAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSPredicate+MGLPrivateAdditions.h"; sourceTree = "<group>"; };
+ 1FCAE2A020B872A400C577DD /* MGLLocationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLLocationManager.h; sourceTree = "<group>"; };
+ 1FCAE2A120B872A400C577DD /* MGLLocationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLLocationManager.m; sourceTree = "<group>"; };
+ 1FCAE2A620B88B3800C577DD /* MGLLocationManager_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLLocationManager_Private.h; sourceTree = "<group>"; };
20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = "<group>"; };
20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
20DABE8A1DF78149007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Root.strings"; sourceTree = "<group>"; };
@@ -1911,6 +1920,9 @@
DA8847EE1CBAFA5100AB86E3 /* MGLTypes.h */,
DA8848111CBAFA6200AB86E3 /* MGLTypes.m */,
35E1A4D71D74336F007AA97F /* MGLValueEvaluator.h */,
+ 1FCAE2A020B872A400C577DD /* MGLLocationManager.h */,
+ 1FCAE2A620B88B3800C577DD /* MGLLocationManager_Private.h */,
+ 1FCAE2A120B872A400C577DD /* MGLLocationManager.m */,
);
name = Foundation;
path = ../darwin/src;
@@ -2227,6 +2239,7 @@
35E79F201D41266300957B9E /* MGLStyleLayer_Private.h in Headers */,
FA68F14A1E9D656600F9F6C2 /* MGLFillExtrusionStyleLayer.h in Headers */,
353933FB1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */,
+ 1FCAE2A820B88B3800C577DD /* MGLLocationManager_Private.h in Headers */,
DA8847EF1CBAFA5100AB86E3 /* MGLAccountManager.h in Headers */,
DA35A2C91CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */,
3510FFEA1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */,
@@ -2237,6 +2250,7 @@
35D3A1E61E9BE7EB002B38EE /* MGLScaleBar.h in Headers */,
0778DD431F67556700A73B34 /* MGLComputedShapeSource.h in Headers */,
DA8848311CBAFA6200AB86E3 /* NSString+MGLAdditions.h in Headers */,
+ 1FCAE2A220B872A400C577DD /* MGLLocationManager.h in Headers */,
DACA86262019218600E9693A /* MGLRasterDEMSource.h in Headers */,
353933F81D3FB79F003F57D7 /* MGLLineStyleLayer.h in Headers */,
92F2C3ED1F0E3C3A00268EC0 /* MGLRendererFrontend.h in Headers */,
@@ -2377,6 +2391,7 @@
DA72620C1DEEE3480043BB89 /* MGLOpenGLStyleLayer.h in Headers */,
35CE61831D4165D9004F2359 /* UIColor+MGLAdditions.h in Headers */,
96E516F32000597100A02306 /* NSDictionary+MGLAdditions.h in Headers */,
+ 1FCAE2A920B88B3800C577DD /* MGLLocationManager_Private.h in Headers */,
96E516F02000595800A02306 /* NSBundle+MGLAdditions.h in Headers */,
96E516F920005A3500A02306 /* MGLFaux3DUserLocationAnnotationView.h in Headers */,
96E516F22000596D00A02306 /* NSException+MGLAdditions.h in Headers */,
@@ -2416,6 +2431,7 @@
968F36B51E4D128D003A5522 /* MGLDistanceFormatter.h in Headers */,
4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */,
DABFB85F1CBE99E500D62B32 /* MGLGeometry.h in Headers */,
+ 1FCAE2A320B872A400C577DD /* MGLLocationManager.h in Headers */,
96E516E02000550C00A02306 /* MGLFeature_Private.h in Headers */,
353933F61D3FB785003F57D7 /* MGLBackgroundStyleLayer.h in Headers */,
DABFB85D1CBE99E500D62B32 /* MGLAccountManager.h in Headers */,
@@ -3000,6 +3016,7 @@
40834BED1FE05E1800C1BD0D /* MMEEventLogger.m in Sources */,
353AFA161D65AB17005A69F4 /* NSDate+MGLAdditions.mm in Sources */,
40834BF41FE05E1800C1BD0D /* MMETrustKitWrapper.m in Sources */,
+ 1FCAE2A420B872A400C577DD /* MGLLocationManager.m in Sources */,
40834BEF1FE05E1800C1BD0D /* MMEEventsManager.m in Sources */,
35D13AC51D3D19DD00AFB4E0 /* MGLFillStyleLayer.mm in Sources */,
DA8848241CBAFA6200AB86E3 /* MGLOfflineStorage.mm in Sources */,
@@ -3126,6 +3143,7 @@
40834C011FE05E1800C1BD0D /* MMEEventLogger.m in Sources */,
35D13AC61D3D19DD00AFB4E0 /* MGLFillStyleLayer.mm in Sources */,
40834C081FE05E1800C1BD0D /* MMETrustKitWrapper.m in Sources */,
+ 1FCAE2A520B872A400C577DD /* MGLLocationManager.m in Sources */,
40834C031FE05E1800C1BD0D /* MMEEventsManager.m in Sources */,
DAA4E42A1CBB730400178DFB /* NSProcessInfo+MGLAdditions.m in Sources */,
DAA4E4211CBB730400178DFB /* MGLOfflineStorage.mm in Sources */,
diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h
index 7beb8b766b..a0afe2d9cc 100644
--- a/platform/ios/src/Mapbox.h
+++ b/platform/ios/src/Mapbox.h
@@ -67,3 +67,4 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
#import "MGLMapSnapshotter.h"
#import "NSExpression+MGLAdditions.h"
#import "NSPredicate+MGLAdditions.h"
+#import "MGLLocationManager.h"