Lir*_*ivo 8 location cllocationmanager ios swift
这是我的locationManager init方法:
func initLocationManager() {
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
Run Code Online (Sandbox Code Playgroud)
在调用此方法之后这一行
println(self.locationManager.location)
Run Code Online (Sandbox Code Playgroud)
打印为零,为什么会这样?它在过去很适合我,我只是在我的应用程序中做了一些更改,它现在不能正常工作..
Edg*_*gar 13
1)CLLocation位置文档 - 如果从未检索到位置数据,则此属性的值为nil.
2)您已为CLLocationManager设置委托.为什么不实现locationManager:didUpdateLocations:并从里面打印最新检索的位置?
3)您使用的是模拟器还是真实的设备?请记住,如果您使用的是模拟器,则可能需要启用模拟位置:

您还可以Custom Location在以下位置找到选项: -Simulator -> Debug -> Location -> Custom Location...