firebase / geofire-objc

GeoFire for Objective-C - Realtime location queries with Firebase
MIT License
436 stars 180 forks source link

iOS swift value change observer #116

Closed nole87 closed 6 years ago

nole87 commented 6 years ago

I need value change observer for all data not only location. On android there is listener for this. I also need for iOS swift. Is it possible to set?

Best regards, Milan

maximkhatskevich commented 6 years ago

@nole87 as far as I understand, GeoFire is specifically for geolocation queries, everything else is out of scope for GeoFire. You should use official Firebase SDK to store and observe any other kind of values in Realtime Database.

maximkhatskevich commented 6 years ago

@nole87 here is the link for you to start https://firebase.google.com/docs/database/ios/start

nole87 commented 6 years ago

I want to get all data for some radius and every change of data for some radius. In android I can do that with geoFire but with iOS swift I can't. It's strange that on android it can be done but on iOS it can't be?

morganchen12 commented 6 years ago

You can do this on iOS, but you may need to listen directly to child changed events in the database.

maximkhatskevich commented 6 years ago

@nole87 I think you are confused a bit about how GeoFire works. It reserves a specific path within your Realtime Database to just store collection of records. Each record is, basically, a pair of coordinate and a key. Then it gives your API to setup geo-location query. When you listen to that query - you, basically, just get those records you put into GeoFire. Each record, again - a pair of coordinate and associated with that coordinate key, which you've put to GeoFire earlier. What is this key - is up to you. An obvious solution is to have all your data stored in Realtime Database (same instance you use for GeoFire or another one - it's up to you), or anywhere else - it does not matter. The fact is - you observe the geo query, and every time you get a notification with another key - you use this key to fetch related data from wherever it comes from. So it's a two steps process - you get a key from GeoFire, and then you fetch the data related to that key from a storage where you keep your data. Does it make sense?

nole87 commented 6 years ago

I know that, I read at https://github.com/firebase/geofire-java as always when dealing with new API, SDK I first research for a while ... In android I find:

geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() ...

For my specific case, I need to have this kind of listener, so in one listener I get all I need. Now on android I use it but on iOS I use orderBy and startAt, end Et to filter +-10 km, but in this way I get all +- 10 km by Y not by X,Y (radius) Because my database is BIG I get lot of data which end iOS user doesn't need! And if I resolve it with radius than I will make big differences on bandwidth for end user but also for firebase costs :)

nole87 commented 6 years ago

Dear,

For me now it's almost urgent to have listener like in java geofire for iOS swift:

Key Entered: The location of a key now matches the query criteria. Key Exited: The location of a key no longer matches the query criteria. Key Moved: The location of a key changed but the location still matches the query criteria. Query Ready: All current data has been loaded from the server and all initial events have been fired. Query Error: There was an error while performing this query, e.g. a violation of security rules.

`geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); }

@Override
public void onKeyExited(String key) {
    System.out.println(String.format("Key %s is no longer in the search area", key));
}

@Override
public void onKeyMoved(String key, GeoLocation location) {
    System.out.println(String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
}

@Override
public void onGeoQueryReady() {
    System.out.println("All initial data has been loaded and events have been fired!");
}

@Override
public void onGeoQueryError(DatabaseError error) {
    System.err.println("There was an error with this query: " + error);
}

});`

Is it big task to do it or not? Who is developing geofire, Firebase team or someone seperate.

nole87 commented 6 years ago

Any help with this?

nole87 commented 6 years ago

I find solution here https://github.com/firebase/geofire-objc/issues/101