刷新用户的位置 - Swift 3

时间:2017-01-13 01:14:32

标签: ios delegates swift3 location cllocationmanager

按下刷新按钮后,我在更新用户位置时遇到问题。我有以下代码。编译器没有显示任何错误,但print after refresh不起作用且没有数据。谁能指出我正确的方向如何解决它?

override func viewDidLoad() {
super.viewDidLoad()

   locationManager.delegate = self
   locationManager.requestWhenInUseAuthorization()
   locationManager.requestLocation()
}

   func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      if let location = locations.first {
        print("Coordinates: \(location)")
      }  
   }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    print("errorer")
    }

然后我有以下刷新代码:

@IBAction func refreshJobData(_ sender: Any) {
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.last {
            print("Coordinates after Refresh: \(location)")
        }

    }

0 个答案:

没有答案