123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // NativeLocation.m
- // Immersal SDK
- //
- // Created by Mikko on 29/05/2020.
- //
- //
- #import "NativeLocation.h"
- double latitude;
- double longitude;
- double altitude;
- double haccuracy;
- double vaccuracy;
- @implementation NativeLocation
- CLLocationManager *locationManager;
- static bool isEnabled = NO;
- - (NativeLocation *)init
- {
- locationManager = [[CLLocationManager alloc] init];
- locationManager.delegate = self;
- locationManager.distanceFilter = kCLDistanceFilterNone;
- locationManager.desiredAccuracy = kCLLocationAccuracyBest;
-
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
- [locationManager requestWhenInUseAuthorization];
-
- return self;
- }
- - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
- {
- /* switch (status) {
- case kCLAuthorizationStatusAuthorizedWhenInUse:
- case kCLAuthorizationStatusAuthorizedAlways:
- isEnabled = YES; break;
- default:
- isEnabled = NO; break;
- }*/
- }
- - (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error;
- {
- isEnabled = NO;
- }
- - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
- {
- CLLocation *location = [locations lastObject];
- latitude = location.coordinate.latitude;
- longitude = location.coordinate.longitude;
- altitude = location.altitude;
- haccuracy = location.horizontalAccuracy;
- vaccuracy = location.verticalAccuracy;
-
- isEnabled = YES;
-
- //NSLog(@"lat: %f long: %f alt: %f", latitude, longitude, altitude);
- }
- - (void)start
- {
- if (locationManager != NULL) {
- [locationManager startUpdatingLocation];
- }
- }
- - (void)stop
- {
- if (locationManager != NULL) {
- [locationManager stopUpdatingLocation];
- }
-
- isEnabled = NO;
- }
- @end
- static NativeLocation* locationDelegate = NULL;
- extern "C"
- {
- void startLocation()
- {
- if (locationDelegate == NULL) {
- locationDelegate = [[NativeLocation alloc] init];
- }
-
- [locationDelegate start];
- }
- void stopLocation()
- {
- if (locationDelegate != NULL) {
- [locationDelegate stop];
- }
- }
-
- double getLatitude()
- {
- return latitude;
- }
- double getLongitude()
- {
- return longitude;
- }
- double getAltitude()
- {
- return altitude;
- }
- double getHorizontalAccuracy()
- {
- return haccuracy;
- }
- double getVerticalAccuracy()
- {
- return vaccuracy;
- }
- bool locationServicesEnabled()
- {
- return isEnabled;
- }
- }
|