This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Add MGLLocationManager and MGLLocationManagerDelegate to Mapbox…
…'s maps SDK.
- Loading branch information
1 parent
4067a61
commit 4529f05
Showing
5 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
self.locationManager.headingOrientation = headingOrientation; | ||
} | ||
|
||
- (CLDeviceOrientation)headingOrientation | ||
{ | ||
return self.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#import "MGLLocationManager.h" | ||
|
||
|
||
@interface MGLCLLocationManager : NSObject<MGLLocationManager> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters