CLLocationManager.location为nil [英] CLLocationManager.location is nil
问题描述
这是我的locationManager init方法:
this is my locationManager init method:
func initLocationManager() {
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
调用此方法后此行
println(self.locationManager.location)
打印没有
为什么会这样?它在过去很适合我,我只是在我的应用程序中做了一些更改,现在效果不好..
prints nil why is that? it worked for me well at the past i just made few changes in my app and it doesn't work well now..
推荐答案
1) CLLocation位置文档
- 如果没有检索到任何位置数据,则此属性的值为nil。
1) CLLocation location documentation - The value of this property is nil if no location data has ever been retrieved.
2)你已经设置CLLocationManager的委托。为什么不实施 locationManager:didUpdateLocations:并从内部打印最新检索的位置?
2) You've set the delegate for CLLocationManager. Why not implement locationManager:didUpdateLocations: and print the latest retrieved location from inside?
3)您使用的是模拟器还是真实设备?请记住,如果您使用的是模拟器,则可能需要启用模拟位置:
3) Are you using a simulator or a real device? Bear in mind that if you are using a simulator you may need to enable simulate location:
您还可以在以下位置找到自定义位置
选项:
- 模拟器 - >调试 - >位置 - >自定义位置...
You can also find a Custom Location
option in:
- Simulator -> Debug -> Location -> Custom Location...
这篇关于CLLocationManager.location为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!