1

I'm trying to further reduce the number of results returned by GeoFire by a privacy value (i.e. if privacy == "public") I haven't found any good solutions about this and didn't see anything of this sort on GeoFire's Github page.

My current solution takes the GeoFire query and iterates through each checking for the value. I'm concerned this will be slow, and frankly doesn't feel right. Is there a more standard way I should be making this query?

circleQuery?.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
    self.annotationLocationRef.child(key).observeSingleEvent(of: .value, with: { (locationSnapshot) in
        if !locationSnapshot.exists() { return }

        self.annotationRef.child(key).observeSingleEvent(of: .value, with: {(annotationSnapshot) in
            if !annotationSnapshot.exists() { return }

            let snapshotValue = annotationSnapshot.value as? NSDictionary
            let privacy = snapshotValue!["privacy"] as? Double

            if privacy == "public" {
                // do stuff
            }
        })
    }) { (error) in
        print(error.localizedDescription)
    }

})
dmr07
  • 1,388
  • 2
  • 18
  • 37
  • `self.annotationRef.queryEqualToValue("public", childKey: "privacy").observeSingleEvent(...)`? From there: https://stackoverflow.com/questions/37577138/firebase-swift-queryequaltovalue-by-childkey-is-not-working – Larme Aug 22 '17 at 16:24
  • Thanks, this helps. If I have 5,000 results, will this make 5,000 network trips? – dmr07 Aug 22 '17 at 16:57
  • GeoFire can only filter by distance from a location, it cannot filter by any additional properties. See my answer here: https://stackoverflow.com/questions/34084347/geofire-how-to-add-extra-conditions-within-the-query/34091633#34091633 – Frank van Puffelen Aug 23 '17 at 06:27
  • @Larme, A little confused. How does the `key` obtained from the previous query get used in your example? I tried `self.annotationRef.child(key).queryEqualToValue("public", childKey: "privacy").observe...` and it doesn't return me anything – dmr07 Aug 24 '17 at 03:52

0 Answers0