summaryrefslogtreecommitdiff
path: root/ios/app/MBXViewController.mm
diff options
context:
space:
mode:
Diffstat (limited to 'ios/app/MBXViewController.mm')
-rw-r--r--ios/app/MBXViewController.mm77
1 files changed, 12 insertions, 65 deletions
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index 2c7bfd6b40..c9973bcb7d 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -21,10 +21,9 @@ static NSArray *const kStyleNames = @[
static NSString *const kStyleVersion = @"v7";
-@interface MBXViewController () <UIActionSheetDelegate, CLLocationManagerDelegate, MGLMapViewDelegate>
+@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>
@property (nonatomic) MGLMapView *mapView;
-@property (nonatomic) CLLocationManager *locationManager;
@end
@@ -66,11 +65,10 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:accessToken];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [self.view addSubview:self.mapView];
-
self.mapView.viewControllerForLayoutGuides = self;
-
+ self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
+ [self.view addSubview:self.mapView];
self.view.tintColor = kTintColor;
self.navigationController.navigationBar.tintColor = kTintColor;
@@ -109,6 +107,8 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
settings->zoom = self.mapView.zoomLevel;
settings->bearing = self.mapView.direction;
settings->debug = self.mapView.isDebugActive;
+ settings->userTrackingMode = self.mapView.userTrackingMode;
+ settings->showsUserLocation = self.mapView.showsUserLocation;
settings->save();
}
}
@@ -119,6 +119,8 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
settings->load();
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(settings->latitude, settings->longitude) zoomLevel:settings->zoom animated:NO];
self.mapView.direction = settings->bearing;
+ self.mapView.userTrackingMode = settings->userTrackingMode;
+ self.mapView.showsUserLocation = settings->showsUserLocation;
[self.mapView setDebugActive:settings->debug];
}
}
@@ -254,40 +256,17 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
- (void)locateUser
{
- if ( ! self.locationManager)
+ if (self.mapView.userTrackingMode == MGLUserTrackingModeNone)
{
- self.locationManager = [CLLocationManager new];
- self.locationManager.delegate = self;
+ self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
}
-
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)
+ else if (self.mapView.userTrackingMode == MGLUserTrackingModeFollow)
{
- [[[UIAlertView alloc] initWithTitle:@"Authorization Denied"
- message:@"Please enable location services for this app in Privacy settings."
- delegate:nil
- cancelButtonTitle:nil otherButtonTitles:@"OK", nil] show];
+ self.mapView.userTrackingMode = MGLUserTrackingModeFollowWithHeading;
}
else
{
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)])
- {
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse)
- {
- [self.locationManager startUpdatingLocation];
- }
- else
- {
- [_locationManager requestWhenInUseAuthorization];
- }
- }
- else
- {
- [self.locationManager startUpdatingLocation];
- }
-#else
- [self.locationManager startUpdatingLocation];
-#endif
+ self.mapView.userTrackingMode = MGLUserTrackingModeNone;
}
}
@@ -305,41 +284,9 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
}
}
-#pragma mark - CLLocationManagerDelegate
-
-- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
-{
- switch (status)
- {
- case kCLAuthorizationStatusAuthorizedAlways:
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- case kCLAuthorizationStatusAuthorizedWhenInUse:
-#endif
- {
- [manager startUpdatingLocation];
- break;
- }
- default:
- {
- }
- }
-}
-
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
-- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
-{
- CLLocation *latestLocation = locations.lastObject;
-
- if ([latestLocation distanceFromLocation:[[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude]] > 100)
- {
- [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latestLocation.coordinate.latitude, latestLocation.coordinate.longitude) zoomLevel:17 animated:YES];
- }
-
- [self.locationManager stopUpdatingLocation];
-}
-
#pragma mark - MGLMapViewDelegate
- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation