diff options
Diffstat (limited to 'ios/app/MBXViewController.mm')
-rw-r--r-- | ios/app/MBXViewController.mm | 78 |
1 files changed, 17 insertions, 61 deletions
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index 6d1175e4f1..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> +@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate> @property (nonatomic) MGLMapView *mapView; -@property (nonatomic) CLLocationManager *locationManager; @end @@ -66,9 +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; @@ -107,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(); } } @@ -117,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]; } } @@ -252,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; } } @@ -303,39 +284,14 @@ 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]; - } +#pragma mark - MGLMapViewDelegate - [self.locationManager stopUpdatingLocation]; +- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation +{ + return YES; } #pragma clang diagnostic pop |