Swift 完成位置管理器的更新

Swift 完成位置管理器的更新,swift,swift2,ios9,cllocationmanager,Swift,Swift2,Ios9,Cllocationmanager,我与更新位置管理器有问题 这就是我想做的。当用户进入视图时,它会请求位置许可,当用户拒绝时,我已经设置了一个代码,我不会在这里发布,因为它可以工作。但如果他接受,我运行一个函数,得到他的经纬度。然后我想运行一个函数,在其中我对一个API进行查询。下面的代码是我制作的 var tolat: Double = 0.0 var tolon: Double = 0.0 let locationManager = CLLocationManager() override func viewDidL

我与更新位置管理器有问题

这就是我想做的。当用户进入视图时,它会请求位置许可,当用户拒绝时,我已经设置了一个代码,我不会在这里发布,因为它可以工作。但如果他接受,我运行一个函数,得到他的经纬度。然后我想运行一个函数,在其中我对一个API进行查询。下面的代码是我制作的

var tolat: Double = 0.0
var tolon: Double = 0.0
let locationManager = CLLocationManager()

   override func viewDidLoad() {
        super.viewDidLoad()


        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters

            locationManager.startUpdatingLocation()

        }


        getData() { result in
            switch result {
            case .Success: self.eventsTable.reloadData()
            case .Failure(let error): break
            }
        }



}


 func getData(completion: Resulty<Void> -> Void) {
        print("the lat \(tolat) and the lon \(tolon)")
        completion(.Success())
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let locValue:CLLocationCoordinate2D = manager.location!.coordinate

    tolat = locValue.latitude
    tolon = locValue.longitude

    locationManager.stopUpdatingLocation()




}
var-tolat:Double=0.0
托隆变量:双=0.0
让locationManager=CLLocationManager()
重写func viewDidLoad(){
super.viewDidLoad()
如果CLLocationManager.locationServicesEnabled(){
locationManager.delegate=self
locationManager.desiredAccuracy=KCallocationAccuracyNearesttenmeters
locationManager.startUpdatingLocation()
}
getData(){结果为
切换结果{
case.Success:self.eventsTable.reloadData()
案例失败(let错误):中断
}
}
}
func getData(完成:结果->作废){
打印(“拉特\(托拉特)和朗\(托伦)”)
完成(.Success())
}
func locationManager(管理器:CLLocationManager,didUpdateLocations位置:[CLLocation]){
让locValue:CLLocationCoordinate2D=manager.location!.coordinate
tolat=locValue.LATIONE
tolon=locValue.longitude
locationManager.StopUpdatengLocation()
}
在视图结束之后

enum Resulty<T> {
    case Success(T)
    case Failure(NSError)
}
枚举结果{
成功案例(T)
案例失败(N错误)
}
所以它打印0.0的纬度和经度。当位置纬度和经度实际有数据时,如何运行
func-getData