0

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

  1. 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.

  2. Is there a way to turn the geoQuery off?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user172902
  • 3,541
  • 9
  • 32
  • 75
  • You'd use the "Query Ready" event for that, it fires when the *initial* key set has been returned. The query will keep synchronizing though, so if your data changes you will receive updates. See https://github.com/firebase/geofire-objc#waiting-for-queries-to-be-ready – Frank van Puffelen Jul 12 '16 at 18:25
  • Thanks again frank. I should've gone through the documentation a bit better – user172902 Jul 13 '16 at 00:54

0 Answers0