|
#include "../ioslocationservice.h" |
|
#include "IOSLocationServiceSingleton.h" |
|
|
|
// implementation of a global location services singleton |
|
|
|
@implementation IOSLocationServiceSingleton |
|
|
|
+(IOSLocationServiceSingleton *) sharedInstance |
|
{ |
|
static IOSLocationServiceSingleton *instance = nil; |
|
static dispatch_once_t onceToken; |
|
dispatch_once(&onceToken, ^{ |
|
instance = [[self alloc] init]; |
|
}); |
|
return instance; |
|
} |
|
|
|
- (id)init { |
|
NSLog(@"[ObjC] Initializing instance of Location Service"); |
|
self = [super init]; |
|
if(self != nil) { |
|
|
|
self.locationManager = [[CLLocationManager alloc] init]; |
|
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; |
|
self.locationManager.distanceFilter = 100; // meters |
|
self.locationManager.delegate = self; |
|
|
|
// pick an authorization method: |
|
[self.locationManager requestWhenInUseAuthorization]; |
|
// [self.locationManager requestAlwaysAuthorization]; |
|
} |
|
return self; |
|
} |
|
|
|
- (void)startUpdatingLocation |
|
{ |
|
NSLog(@"Starting location updates"); |
|
[self.locationManager startUpdatingLocation]; |
|
} |
|
|
|
- (void)stopUpdatingLocation { |
|
NSLog(@"Stopping location updates"); |
|
[self.locationManager stopUpdatingLocation]; |
|
} |
|
|
|
- (void)locationManager:(CLLocationManager *)manager |
|
didFailWithError:(NSError *)error |
|
{ |
|
#pragma unused(manager) |
|
NSLog(@"Location service failed with error %@", error); |
|
} |
|
|
|
- (void)dealloc { |
|
[self.locationManager stopUpdatingLocation]; |
|
NSLog(@"Deallocating IOSLocationServiceSingleton"); |
|
[super dealloc]; |
|
} |
|
|
|
- (void)locationManager:(CLLocationManager *)manager |
|
didUpdateLocations:(NSArray*)locations |
|
{ |
|
#pragma unused(manager) |
|
CLLocation *location = [locations lastObject]; |
|
NSLog(@"Location Update: Latitude %+.6f, Longitude %+.6f\n", |
|
location.coordinate.latitude, |
|
location.coordinate.longitude); |
|
[self setCurrentLocation:location]; |
|
} |
|
@end |
|
|
|
/////////////////////// |
|
|
|
// C++ wrapper |
|
|
|
namespace IOSLocationService { |
|
|
|
LocationService::LocationService() { |
|
[[IOSLocationServiceSingleton sharedInstance] startUpdatingLocation]; |
|
} |
|
|
|
Loc LocationService::getCurrentLocation() { |
|
CLLocation* clloc = [IOSLocationServiceSingleton sharedInstance].currentLocation; |
|
Loc loc; |
|
loc.latitude = clloc.coordinate.latitude; |
|
loc.longitude = clloc.coordinate.longitude; |
|
return loc; |
|
} |
|
|
|
} // namespace IosLocationService |