Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active April 13, 2019 20:45
Show Gist options
  • Save paulw11/ea199a76b8e624ebb2ff3d809f022b13 to your computer and use it in GitHub Desktop.
Save paulw11/ea199a76b8e624ebb2ff3d809f022b13 to your computer and use it in GitHub Desktop.
func startUpdatingLocation() {
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.activityType = .fitness
self.locationManager.startUpdatingLocation()
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse {
self.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else {
return
}
DispatchQueue.main.async {
self.accuracyLabel.text = "\(location.horizontalAccuracy)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment