Getting Nearby Users Android With Firebase
i am using firebase realtime database to store two types of users for two apps, users A will use App A to update their info and such, and users B will use app B to search nearby us
Solution 1:
For anyone who will find this useful i managed to do it by placing the addValueEventListener
method of firebase within the addQueryEventListener
and pass the String key that is returned by the onKeyEntered
method as part of the path in my database reference,
something like this
temp2=FirebaseDatabase.getInstance().getReference("users/A");
GeoFire geofire=newGeoFire(temp2.child("A_location"));
GeoQuery geoQuery=geofire.queryAtLocation(newGeoLocation(lat,lng),10);
geoQuery.addGeoQueryEventListener(newGeoQueryEventListener() {
@OverridepublicvoidonKeyEntered(String key, GeoLocation location) {
temp2.child(key).addValueEventListener(newValueEventListener() {
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
Person person1 = dataSnapshot.getValue(Person.class);
String name = person1.getName();
String imageUri = person1.getImageUri();
System.out.print(name + " " + imageUri);
Toast.makeText(getActivity(),name,Toast.LENGTH_LONG).show();
personList.add(newPerson(name, imageUri));
RVAdapter adapter=newRVAdapter(getActivity(),personList);
rv.setAdapter(adapter);
}
My only question is now is this method efficient if there are alot of users?
Post a Comment for "Getting Nearby Users Android With Firebase"