SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSiOSGpsDelegate Class Reference

#import <SENSiOSGpsDelegate.h>

Inherits NSObject, and <CLLocationManagerDelegate>.

Instance Methods

(BOOL) - start
 Starts the location data update. More...
 
(void- stop
 Stops the location data update. More...
 
(void- askPermission
 
(id) - init [implementation]
 
(void- setupLocationManager [implementation]
 Starts the location data update if the interval time > 0 else it stops. More...
 
(void- locationManager:didUpdateToLocation:fromLocation: [implementation]
 
(void- locationManager:didFailWithError: [implementation]
 
(void- locationManager:didChangeAuthorizationStatus: [implementation]
 

Properties

std::function< void(double, double, double, double)> updateCB
 
std::function< void(bool)> permissionCB
 

Private Attributes

CLLocationManager * _locationManager
 
BOOL _running
 

Detailed Description

Definition at line 6 of file SENSiOSGpsDelegate.h.

Method Documentation

◆ askPermission

- (void) askPermission

Definition at line 7 of file SENSiOSGpsDelegate.mm.

42 {
43  // for iOS 8, specific user level permission is required,
44  // "when-in-use" authorization grants access to the user's location.
45  // important: be sure to include NSLocationWhenInUseUsageDescription along with its
46  // explanation string in your Info.plist or startUpdatingLocation will not work
47  if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
48  {
49  [_locationManager requestWhenInUseAuthorization];
50  }
51 }
CLLocationManager * _locationManager

◆ init

- (id) init
implementation

Definition at line 7 of file SENSiOSGpsDelegate.mm.

15 {
16  //Initialize the parent class(es) up the hierarchy and create self:
17  self = [super init];
18 
19  //Initialize members (not necessary with ARC)
20  _locationManager = nil;
21  _running = NO;
22  if (self)
23  {
24  [self setupLocationManager];
25  }
26 
27  return self;
28 }

◆ locationManager:didChangeAuthorizationStatus:

- (void) locationManager: (CLLocationManager*)  manager
didChangeAuthorizationStatus: (CLAuthorizationStatus)  status 
implementation

Definition at line 7 of file SENSiOSGpsDelegate.mm.

111  :(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
112 {
113  //callback permission status
114  if (status == kCLAuthorizationStatusAuthorizedAlways ||
115  status == kCLAuthorizationStatusAuthorizedWhenInUse)
116  {
117  if (_permissionCB)
118  _permissionCB(true);
119  }
120  else
121  {
122  if (_permissionCB)
123  _permissionCB(false);
124  }
125 }

◆ locationManager:didFailWithError:

- (void) locationManager: (CLLocationManager*)  manager
didFailWithError: (NSError*)  error 
implementation

Definition at line 7 of file SENSiOSGpsDelegate.mm.

98  :(CLLocationManager*)manager didFailWithError:(NSError*)error
99 {
100  // The location "unknown" error simply means the manager is currently unable to get the location.
101  // We can ignore this error for the scenario of getting a single location fix, because we already have a
102  // timeout that will stop the location manager to save power.
103  //
104  if ([error code] != kCLErrorLocationUnknown)
105  {
106  printf("**** locationManager didFailWithError ****\n");
107  [self stop];
108  }
109 }

◆ locationManager:didUpdateToLocation:fromLocation:

- (void) locationManager: (CLLocationManager*)  manager
didUpdateToLocation: (CLLocation*)  newLocation
fromLocation: (CLLocation*)  oldLocation 
implementation

Definition at line 7 of file SENSiOSGpsDelegate.mm.

80  :(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
81 {
82  //printf("horizontalAccuracy: %f\n", newLocation.horizontalAccuracy);
83 
84  // negative horizontal accuracy means no location fix
85  if (newLocation.horizontalAccuracy > 0.0)
86  {
87  //callback here
88  if (_updateCB)
89  {
90  _updateCB(newLocation.coordinate.latitude,
91  newLocation.coordinate.longitude,
92  newLocation.altitude,
93  newLocation.horizontalAccuracy);
94  }
95  }
96 }

◆ setupLocationManager

- (void) setupLocationManager
implementation

Starts the location data update if the interval time > 0 else it stops.

Definition at line 7 of file SENSiOSGpsDelegate.mm.

32 {
33  // Init location manager
34  _locationManager = [[CLLocationManager alloc] init];
35  _locationManager.delegate = self;
36  _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
37 
38  [self askPermission];
39 }

◆ start

- (BOOL) start

Starts the location data update.

Definition at line 7 of file SENSiOSGpsDelegate.mm.

55 {
56  if (_locationManager == nil)
57  return NO;
58 
59  if (!_running)
60  {
61  [_locationManager startUpdatingLocation];
62  _running = true;
63  printf("Starting Location Manager\n");
64  }
65 
66  return YES;
67 }

◆ stop

- (void) stop

Stops the location data update.

Definition at line 7 of file SENSiOSGpsDelegate.mm.

71 {
72  if (_running)
73  {
74  [_locationManager stopUpdatingLocation];
75  _running = false;
76  printf("Stopping Location Manager\n");
77  }
78 }

Member Data Documentation

◆ _locationManager

- (CLLocationManager*) _locationManager
private

Definition at line 6 of file SENSiOSGpsDelegate.mm.

◆ _running

- (BOOL) _running
private

Definition at line 7 of file SENSiOSGpsDelegate.mm.

Property Documentation

◆ permissionCB

- (function<void(bool)>) SENSiOSGpsDelegate:
readwritenonatomicassign

Definition at line 13 of file SENSiOSGpsDelegate.h.

◆ updateCB

- (function<void(double, double, double, double)>) SENSiOSGpsDelegate:
readwritenonatomicassign

Definition at line 12 of file SENSiOSGpsDelegate.h.


The documentation for this class was generated from the following files: