summaryrefslogtreecommitdiff
path: root/platform/ios/app
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2018-07-20 14:14:43 -0700
committerGitHub <noreply@github.com>2018-07-20 14:14:43 -0700
commit681e0141de63d0d5a545e87c40216163b2d63fc6 (patch)
tree0253e9980ca3c8a75d8f2e04dae8d69f1ef667bd /platform/ios/app
parentbbccce18c4d064054726f66e0b9b41cebfe314e4 (diff)
downloadqtlocation-mapboxgl-681e0141de63d0d5a545e87c40216163b2d63fc6.tar.gz
[ios] Mapbox's Location Manager new API. (#12013)
* [ios] The new location manager API provides two new protocols MGLLocationManager and MGLLocationManagerDelegate to handle the location cycle and updates respectively. This enables developers to chose the appropriate location provider according to their needs, or transition between outdoors/indoors location updates. It does provide a default implementation based on CLLocationManager.
Diffstat (limited to 'platform/ios/app')
-rw-r--r--platform/ios/app/MBXCustomLocationViewController.h5
-rw-r--r--platform/ios/app/MBXCustomLocationViewController.m174
-rw-r--r--platform/ios/app/MBXViewController.m7
-rw-r--r--platform/ios/app/Main.storyboard16
-rw-r--r--platform/ios/app/simple_route.json184
5 files changed, 386 insertions, 0 deletions
diff --git a/platform/ios/app/MBXCustomLocationViewController.h b/platform/ios/app/MBXCustomLocationViewController.h
new file mode 100644
index 0000000000..ae6c14fe2c
--- /dev/null
+++ b/platform/ios/app/MBXCustomLocationViewController.h
@@ -0,0 +1,5 @@
+#import <UIKit/UIKit.h>
+
+@interface MBXCustomLocationViewController : UIViewController
+
+@end
diff --git a/platform/ios/app/MBXCustomLocationViewController.m b/platform/ios/app/MBXCustomLocationViewController.m
new file mode 100644
index 0000000000..34887c5736
--- /dev/null
+++ b/platform/ios/app/MBXCustomLocationViewController.m
@@ -0,0 +1,174 @@
+#import "MBXCustomLocationViewController.h"
+
+#import <Mapbox/Mapbox.h>
+
+@interface MBXCustomLocationManager : NSObject<MGLLocationManager>
+@end
+
+@interface MBXCustomLocationManager()
+
+@property (nonatomic) CLLocationManager *locationManager;
+@property (nonatomic, strong) NSTimer *locationUpdateTimer;
+@property (nonatomic) NSUInteger index;
+@property (strong, nonatomic) NSDictionary *routeCoordinates;
+@property (strong, nonatomic) NSArray *coordinates;
+
+@end
+
+@implementation MBXCustomLocationManager
+
+@synthesize delegate;
+
+- (instancetype)init
+{
+ if (self = [super init]) {
+ _locationManager = [[CLLocationManager alloc] init];
+ _index = 0;
+ }
+ 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 loadRouteCoordinates];
+ self.locationUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.8
+ target:self
+ selector:@selector(updateLocation)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)stopUpdatingHeading
+{
+ [self.locationManager stopUpdatingHeading];
+}
+
+- (void)stopUpdatingLocation
+{
+ [self.locationUpdateTimer invalidate];
+ self.locationUpdateTimer = nil;
+}
+
+- (void)dismissHeadingCalibrationDisplay
+{
+ [self.locationManager dismissHeadingCalibrationDisplay];
+}
+
+- (void)dealloc
+{
+ [self.locationManager stopUpdatingLocation];
+ [self.locationManager stopUpdatingHeading];
+ self.delegate = nil;
+}
+
+#pragma mark - Location Updates
+
+- (void)loadRouteCoordinates
+{
+ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"simple_route" ofType:@"json"];
+ NSData *data = [NSData dataWithContentsOfFile:filePath];
+ _routeCoordinates = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
+ _coordinates = [self.routeCoordinates objectForKey:@"coordinates"];
+}
+
+- (void)updateLocation
+{
+ if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateLocations:)]) {
+
+ if (self.index >= [self.coordinates count] ) {
+ self.index = 0;
+ self.coordinates = [[self.coordinates reverseObjectEnumerator] allObjects];
+ }
+ NSArray *loc = self.coordinates[self.index];
+ CLLocationDegrees latitude = [[loc objectAtIndex:1] doubleValue];
+ CLLocationDegrees longitude = [[loc objectAtIndex:0] doubleValue];
+ CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
+ self.index++;
+ [self.delegate locationManager:self didUpdateLocations:@[location]];
+ }
+}
+
+- (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;
+}
+
+- (void)locationManager:(CLLocationManager *)locationManager didFailWithError:(nonnull NSError *)error {
+ if ([self.delegate respondsToSelector:@selector(locationManager:didFailWithError:)]) {
+ [self.delegate locationManager:self didFailWithError:error];
+ }
+}
+
+@end
+
+@interface MBXCustomLocationViewController ()
+
+@property (strong, nonatomic) MGLMapView *mapView;
+
+@end
+
+@implementation MBXCustomLocationViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
+
+ self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ MBXCustomLocationManager *mbxLocationManager = [[MBXCustomLocationManager alloc] init];
+ self.mapView.locationManager = mbxLocationManager;
+ // Set the map’s center coordinate and zoom level.
+ [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(37.788380, -122.400121)
+ zoomLevel:13
+ animated:NO];
+
+ [self.view addSubview:self.mapView];
+ self.mapView.showsUserLocation = YES;
+}
+
+- (void)viewWillDisappear:(BOOL)animated {
+ self.mapView.showsUserLocation = NO;
+}
+
+@end
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 167f07d296..71bad66aee 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -98,6 +98,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousLocalizeLabels,
MBXSettingsMiscellaneousShowSnapshots,
MBXSettingsMiscellaneousShouldLimitCameraChanges,
+ MBXSettingsMiscellaneousShowCustomLocationManager,
MBXSettingsMiscellaneousPrintLogFile,
MBXSettingsMiscellaneousDeleteLogFile,
};
@@ -444,6 +445,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[NSString stringWithFormat:@"Show Labels in %@", (_localizingLabels ? @"Default Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
@"Show Snapshots",
[NSString stringWithFormat:@"%@ Camera Changes", (_shouldLimitCameraChanges ? @"Unlimit" : @"Limit")],
+ @"View Route Simulation",
]];
if (self.debugLoggingEnabled)
@@ -682,6 +684,11 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self performSegueWithIdentifier:@"ShowSnapshots" sender:nil];
break;
}
+ case MBXSettingsMiscellaneousShowCustomLocationManager:
+ {
+ [self performSegueWithIdentifier:@"ShowCustomLocationManger" sender:nil];
+ break;
+ }
case MBXSettingsMiscellaneousShouldLimitCameraChanges:
{
self.shouldLimitCameraChanges = !self.shouldLimitCameraChanges;
diff --git a/platform/ios/app/Main.storyboard b/platform/ios/app/Main.storyboard
index 72c5cd013f..3e8a0ad02a 100644
--- a/platform/ios/app/Main.storyboard
+++ b/platform/ios/app/Main.storyboard
@@ -107,6 +107,7 @@
<outlet property="hudLabel" destination="58y-pX-YyB" id="aGG-7a-bZR"/>
<outlet property="mapView" destination="kNe-zV-9ha" id="VNR-WO-1q4"/>
<segue destination="zvf-Qd-4Ru" kind="show" identifier="ShowSnapshots" id="hzX-Jp-UJq"/>
+ <segue destination="dgL-Bu-te0" kind="show" identifier="ShowCustomLocationManger" id="kDM-0K-hSf"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="AAd-8J-9UU" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -432,6 +433,21 @@
</objects>
<point key="canvasLocation" x="1365.5999999999999" y="1083.5082458770617"/>
</scene>
+ <!--Custom Location View Controller-->
+ <scene sceneID="TUi-Dc-6uA">
+ <objects>
+ <viewController id="dgL-Bu-te0" customClass="MBXCustomLocationViewController" sceneMemberID="viewController">
+ <view key="view" contentMode="scaleToFill" id="ero-1d-Jm5">
+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+ <viewLayoutGuide key="safeArea" id="t2S-ES-YuE"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="RtO-ic-8Nc" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="2073" y="1082"/>
+ </scene>
</scenes>
<resources>
<image name="TrackingLocationOffMask.png" width="23" height="23"/>
diff --git a/platform/ios/app/simple_route.json b/platform/ios/app/simple_route.json
new file mode 100644
index 0000000000..8b910dbdaf
--- /dev/null
+++ b/platform/ios/app/simple_route.json
@@ -0,0 +1,184 @@
+{
+ "coordinates":[
+ [
+ -122.39899,
+ 37.787357
+ ],
+ [
+ -122.398818,
+ 37.78722
+ ],
+ [
+ -122.398794,
+ 37.7872
+ ],
+ [
+ -122.398259,
+ 37.786773
+ ],
+ [
+ -122.398984,
+ 37.786206
+ ],
+ [
+ -122.399053,
+ 37.786151
+ ],
+ [
+ -122.399379,
+ 37.785888
+ ],
+ [
+ -122.399614,
+ 37.785697
+ ],
+ [
+ -122.399884,
+ 37.785478
+ ],
+ [
+ -122.400382,
+ 37.78509
+ ],
+ [
+ -122.400478,
+ 37.785015
+ ],
+ [
+ -122.400599,
+ 37.785111
+ ],
+ [
+ -122.4012,
+ 37.785587
+ ],
+ [
+ -122.401495,
+ 37.785825
+ ],
+ [
+ -122.401705,
+ 37.785993
+ ],
+ [
+ -122.402041,
+ 37.786261
+ ],
+ [
+ -122.402476,
+ 37.786603
+ ],
+ [
+ -122.402573,
+ 37.78668
+ ],
+ [
+ -122.403019,
+ 37.787031
+ ],
+ [
+ -122.403315,
+ 37.78728
+ ],
+ [
+ -122.403358,
+ 37.787324
+ ],
+ [
+ -122.403382,
+ 37.787356
+ ],
+ [
+ -122.403398,
+ 37.787392
+ ],
+ [
+ -122.403405,
+ 37.787425
+ ],
+ [
+ -122.403415,
+ 37.787486
+ ],
+ [
+ -122.403434,
+ 37.787654
+ ],
+ [
+ -122.403436,
+ 37.787676
+ ],
+ [
+ -122.40344,
+ 37.787698
+ ],
+ [
+ -122.403444,
+ 37.787729
+ ],
+ [
+ -122.403464,
+ 37.787825
+ ],
+ [
+ -122.403476,
+ 37.787877
+ ],
+ [
+ -122.403497,
+ 37.787965
+ ],
+ [
+ -122.403591,
+ 37.788436
+ ],
+ [
+ -122.403684,
+ 37.788901
+ ],
+ [
+ -122.403774,
+ 37.789349
+ ],
+ [
+ -122.403798,
+ 37.789469
+ ],
+ [
+ -122.403872,
+ 37.789833
+ ],
+ [
+ -122.404232,
+ 37.789788
+ ],
+ [
+ -122.405435,
+ 37.789635
+ ],
+ [
+ -122.406,
+ 37.789562
+ ],
+ [
+ -122.406982,
+ 37.789436
+ ],
+ [
+ -122.407475,
+ 37.789373
+ ],
+ [
+ -122.408599,
+ 37.789231
+ ],
+ [
+ -122.408616,
+ 37.789229
+ ],
+ [
+ -122.408451,
+ 37.788454
+ ]
+ ]
+} \ No newline at end of file