I tried to populate the recyclerview with geoquery and I set the radius of geoquery only 0.1 so I would get only 1 item from firebase (and it is working).
But, why were all IDs printed and looped based on item that I found in firebase.
View the end result in emulator
reference = FirebaseDatabase.getInstance().getReference("Users").child("Location");
GeoFire geoFire = new GeoFire(reference);
double my_lat = -6.2629133;
double my_lon = 106.8355483;
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(my_lat, my_lon), 0.1);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Query locationDataQuery = FirebaseDatabase.getInstance().getReference("Users").child("Cleaner");
locationDataQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren()){
Sitter p = dataSnapshot1.getValue(Sitter.class);
list.add(p);
}
sitterAdapter = new SitterAdapter(MainActivity.this, list);
sitter_place.setAdapter(sitterAdapter);
Toast.makeText(getApplicationContext(), "Data Ada", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "Data Kosong", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
I expect the output only 1 item that I found in firebase based on radius that I set for my geoquery.