我无法让GeoFirestore
处理我的项目(请注意,这是GeoFirestore-iOS
,而不是JavaScript库)。
KeyEntered
事件不在查询中时会触发。如果该区域与文档位置所处的位置相邻,则即使距离酒店约1公里,也会触发该事件。
第一次触发KeyEntered
事件后,即使将查询区域移离该位置很大距离,该事件仍继续触发。在调试代码时,我可以看到在updateLocations()
函数中info.isInQuery
设置为false,但是事件仍然被触发吗?对于键输入的事件,它有时还返回两个相同的对象。我希望这与相同的问题有关。
我不确定自己在做什么错。这是我设置查询的地方:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
self.currentLocation = CLLocation(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
if self.activeSearchQuery == "Current Location" && self.initialLocationsUpdate == true {
centerMapOnLocation(location: currentLocation)
self.regionQuery = GlobalDatabase.geoFirestore.query(inRegion: self.mapView.region)
let queryHandle = self.regionQuery.observe(.documentEntered, with: { (key, location) in
print("The document with documentID '\(key)' entered the search area and is at location '\(location)'")
// Get document here
}
})
self.initialLocationsUpdate = false
}
}
然后,当用户移动地图位置时,我会更新区域:
self.regionQuery.region = self.mapView.region
我对这个库的内部运作不是很熟悉。我希望查询将非常准确,并且不会返回位于查询之外的任何文档。有人知道我在做什么吗?