I am using geoFire3.0 to query nearby data based on users location using the following code
let ref = DataService.ds.REF_LOCATION
let geoFire = GeoFire(firebaseRef: ref)
let center = CLLocation(latitude: lat, longitude: long)
let circleQuery = geoFire.queryAtLocation(center, withRadius: SEARCH_RADIUS)
_ = circleQuery.observeEventType(GFEventType.KeyEntered) { (key: String!, location: CLLocation!) in
The problem is that this query is fired every time a data is found that meets the criteria. I have to keep track of all the data and put it inside an array and use sortInPlace to sort it. This is all fine if I have a small amount of data and want to download everything and use the data after everything is sorted.
However, I see two major issue with this 1. If a new entry is added to firebase by anyone within the search radius, this will be triggered which can be annoying. (As it is not observe single event) 2. I want to achieve pagination. What I have in mind is download all geoData from around me first and load them in my app with pagination.
So my question is
Is there a way to detect that all entry in firebase from the geoQuery has been downloaded? Say if I have unknown amount of geoData in firebase, I receive a notification when everything is downloaded so I can turn the geoQuery off.
Is there a way to turn the geoQuery off?