我试图在Geofire的帮助下从Firebase取下我的所有位置结果。不幸的是我无法这样做。我已阅读所有文档但没有运气,为什么我无法让它工作。
我建立了我的geoFireRef ......
var geoFire: GeoFire!
var geoFireRef: DatabaseReference!
geoFireRef = Database.database().reference()
geoFire = GeoFire(firebaseRef: geoFireRef)
我使用内置方法在Firebase中设置我的位置...
geoFire.setLocation(location, forKey: "\(myKey)")
但是当我尝试从数据库中提取信息时,我无法这样做。
func mapView(_ mapView: MKMapView, regionWillChangeAnimated animated:
Bool) {
let loc = CLLocation(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude)
showGamesOnMap(location: loc)
}
func showGamesOnMap(location: CLLocation) {
let circleQuery = geoFire.query(at: location, withRadius: 2.5)
//ABLE TO PRINT HERE
Swift.print("Starting Query")
circleQuery.observe(.keyEntered, with: { (key: String?, location: CLLocation?) in
//UNABLE TO PRINT HERE
Swift.print("Key '\(key!)' entered the search are and is at location '\(location!)'")
})
}
以下是我在数据库中建立的规则。
{
"rules": {
".read": true,
".write": true,
".indexOn": ["g"]
}
}
我已经调试了两天多没有运气了。提前谢谢。