3

After reading these questions:

Associate Geofire location with Firebase entry

Filtering results with Geofire + Firebase

I understand that for a given instance, the location data and regular data for that object must be kept separate, and therefore I must have different listeners. The first to find the location data, and then one for each of the objects that corresponds to those found by the location query.

However, my question is regarding listeners for the actual data itself, not the location data. For the purpose of an example, lets say I have an app that finds a list of 'Restaurant' objects near the user's current location. I understand that this must be done using GeoFire, but is it necessary to have a single event listener for each of the returned snapshots to retrieve the additional data?

To elaborate, what if I want to know when any of the other aspects of the restaurants change (rating, hours, seats available)? A single event value listener will not do this as it will not be listening for constant changes on these restaurants.

What would be the best way to go about this?

Community
  • 1
  • 1
Jacob
  • 2,338
  • 2
  • 22
  • 39
  • 1
    The best way is indeed to attach listeners. Typically these are single-value listeners, but regular listeners will also work. Just don't listen for thousands of restaurants, which would lead to an overwhelming amount of data on the iPhone screen anyway. – Frank van Puffelen Feb 04 '16 at 05:15
  • @FrankvanPuffelen would around 50 or so listeners be okay? I don't anticipate displaying more results than that to begin with. Also, just to clarify, if I am creating the restaurants using childbyautoid, this same Id would be the key for the GeoFire information for the corresponding restaurant? – Jacob Feb 04 '16 at 05:17
  • You can use any key. Geofire just associates the key you give it, with the location you specify. – Frank van Puffelen Feb 04 '16 at 05:20
  • @FrankvanPuffelen But using the same key would make them easier to associate when I need to know what references to add the listeners for, correct? – Jacob Feb 04 '16 at 05:21
  • Yup. In fact, I wouldn't know how you'd associate them if you're using different keys. ;-) – Frank van Puffelen Feb 04 '16 at 05:42
  • @FrankvanPuffelen How do I detect if one of these keys has been removed in the data location. Do I use a value listener? I'm not sure if this is called when the key is removed. – Jacob Feb 04 '16 at 21:22
  • You're already attaching value listener, aren't you. Those will fire. If you'r having trouble an [mcve](http://stackoverflow.com/help/mcve) would help. – Frank van Puffelen Feb 05 '16 at 01:53
  • @FrankvanPuffelen But the value listener will not let me know if the data at that location was removed, will it? – Jacob Feb 05 '16 at 23:24
  • It will fire with a `null` value when the value is removed. But you can test all this by writing a minimal piece of code. If that doesn't work: post the code and it'll all be a lot less theoretical. – Frank van Puffelen Feb 05 '16 at 23:40

0 Answers0