Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ViewController: UIViewController, CLLocationManagerDelegate {
//MARK: Var Declarations
let testDefaultCity = "London"
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// For use in foreground
self.locationManager.requestAlwaysAuthorization()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.distanceFilter = 1.0
if (CLLocationManager.authorizationStatus() == .AuthorizedAlways ||
CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse) {
locationManager.startUpdatingLocation()
} else {
print("ERROR HERE GO FIX IT")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//Everytime you force unwrap, a puppy dies. Use if lets or guards
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
print("yes")
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if (CLLocationManager.authorizationStatus() == .AuthorizedAlways ||
CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse) {
locationManager.startUpdatingLocation()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.