【发布时间】:2016-08-07 19:25:21
【问题描述】:
所以我不知道发生了什么。我的代码工作得非常好,然后我在故事板中工作了一段时间,突然我开始收到错误,即我的 CLLocation 在展开时总是为零。我做了所有我能想到或在网上读到的东西。
- 已添加到 .plist
- 在不同位置复制代码
- 将 didUpdateLocations 移至 viewDidLoad
如果我将方案更新为具有默认位置,那么它只会一直使用默认位置,并且永远不会更新我当前的位置,当我在实际设备上尝试时也是如此,但如果我将其保留为无,则代表调用错误didFailWithError 的方法,表示返回的值为零。我在这里丢了。请帮忙。
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("In the location, seems we got some shit --> didFailWithError: \(error.description)")
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue : CLLocationCoordinate2D = locationManager.location!.coordinate
let geoFire = GeoFire(firebaseRef: self.geofireRef.child("Posts"))
let center = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude)
let circleQuery = geoFire.queryAtLocation(center, withRadius: 10)
circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
print("Key '\(key)' entered the search area and is at location '\(location)'")
})
self.locationManager.stopUpdatingLocation()
}
【问题讨论】:
-
您正在监控重大的位置变化。这些只会在一段时间后发生。你知道吗?在模拟器中,最多可能需要 5 分钟才能看到任何更新。这些可能真的不准确,您不会立即看到更新。尝试在不显着位置更改的情况下进行。在停止之前,我还会先处理 didUpdateLocations 上的所有内容。
-
我不知道,但这些只是尝试任何事情的额外尝试。根据您的建议进行更改后,我仍然遇到同样的问题。
-
我已经更新了我的代码,但仍然遇到同样的问题
-
请发布代码,而不是截图。您是否检查过您的应用设置以确认您没有拒绝位置权限?地图可以在设备上找到您的位置吗?当您在设备上模拟位置时,有时位置服务会受到干扰,您需要重新启动设备才能使其再次工作。在模拟器上你总是需要模拟一个位置
-
对不起。我会更新帖子。如何进入应用设置以检查我的位置是否被拒绝?
标签: ios swift core-location cllocationmanager