I have a Firebase Realtime Database with a set of Items who related to locations on a Googlemap. So every child in the Firebase have a data structure like this.
-item
latitude:"5511231165654"
longitude:"516891812013216"
postalcode: "10013"
cityname: "New York"
In my app every item from the database, where added to the related location on the Googlemap in form of a marker. Now i think it is not a good idea to send all Items to all users. It´s more efficiently to send the user´s only these items that are relevant for them. These items are that one who are in the same area with the user, in this case same area means same postal code.
To handle this i build this Query
Query sortedByLocation = myRef.orderByChild("postalcode").equalTo(currentpostalcode);
sortedByLocation.addListenerForSingleValueEvent(
new ValueEventListener() {
.
. do something
.
}
i got the currentpostalcode from a Geocoder also the cityname. Now the problem is sometimes the Geocoder can´t decode the postal code and return null for it, but it allways return a cityname. So i changed the query to
Query sortedByLocation = myRef.orderByChild("cityname").equalTo(currentcity);
So how can i combine these two querys ? I want to do something like this:
is postalcode == null than check for cityname
The other Question will be, it is possible to retrieve data manually at need ?
Imagine the user start the app, the app now get all items who are in the same area with the user, but now the user left this area and go into a other area.
How can i trigger to retrieve the new data for this new area without to restart the app ?