title: How to get location coordinates in macOS、swift
body: <p>I need to get the geographical coordinates on Mac OS. Here is my code, but an error is reported when running: domain = kclerrordomain code = 0 "(null)"</p>
  
  <pre><code>import Cocoa
  import CoreLocation
  
      let locationManager:CLLocationManager = CLLocationManager()
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
          //设置定位服务管理器代理
          locationManager.delegate = self
          //设置定位进度
          locationManager.desiredAccuracy = kCLLocationAccuracyBest //最佳定位
          //更新距离
  //        locationManager.distanceFilter = 100
          //发出授权请求
          locationManager.requestAlwaysAuthorization()
  
          if (CLLocationManager.locationServicesEnabled()){
              //允许使用定位服务的话，开始定位服务更新
  
  //            print("定位开始")
  
          }
      }
  
  extension ViewController:CLLocationManagerDelegate{
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
          //获取最新的坐标
          let currLocation : CLLocation = locations.last!  // 持续更新
          print("纬度:\(currLocation.coordinate.latitude) 纬度:\(currLocation.coordinate.longitude) 海拔:\(currLocation.altitude) 水平精度:\(currLocation.horizontalAccuracy) 垂直精度:\(currLocation.verticalAccuracy) 方向:\(currLocation.course) 速度:\(currLocation.speed)")
      }
      func locationManager(_ manager: CLLocationManager,
                          didChangeAuthorization status: CLAuthorizationStatus) {
          print("location manager auth status changed to:" )
          switch status {
              case .restricted:
                  print("status restricted")
              case .denied:
                  print("status denied")
  
              case .authorized:
                  print("已授权")
                  locationManager.startUpdatingLocation()
              case .notDetermined:
                  print("status not yet determined")
  
              default:
                  print("unknown state: \(status)")
          }
      }
  
      func locationManager(_ manager: CLLocationManager,
                              didFailWithError error: Error) {
          print( "location manager failed with error \(error)" )
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lxJ2E.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>When running application:
  <a href="https://i.stack.imgur.com/HOyll.png" rel="nofollow noreferrer">enter image description here</a></p>