Skip to content

Instantly share code, notes, and snippets.

@alimovlex
Last active February 15, 2023 16:41
Show Gist options
  • Select an option

  • Save alimovlex/e9e6db7080874cd8a9429bf9c1b56bac to your computer and use it in GitHub Desktop.

Select an option

Save alimovlex/e9e6db7080874cd8a9429bf9c1b56bac to your computer and use it in GitHub Desktop.
The location service class for iOS devices written in Swift.
/*
* Copyright (C) 2023 Recompile.me.
* All rights reserved.
*/
import CoreLocation
class Navigator: NSObject, CLLocationManagerDelegate {
let locationManager = CLLocationManager();
var currentLocation: CLLocation!;
override init() {
super.init();
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
func locationAuthStatus() {
locationManager.requestWhenInUseAuthorization();
locationManager.startMonitoringSignificantLocationChanges();
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
currentLocation = locationManager.location;
print(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
} else {
locationManager.requestWhenInUseAuthorization();
locationAuthStatus();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment