I am trying to query the nearest documenst to the user location using geofirestore
, my code fetch 1 document only, and as you see in the code I set the radius to 100km, and I set the location of the document from the same location.
This is the document I am querying it
And this is the other document with the same radius
I tried to print the snapshot
result in a map and it's only print 1 document
here I send the document id to build the query
into recyclerView
Map<String,Object> stringIntegerMap=new HashMap<>();
private void getNearestEstate(){
GeoQuery geoQuery = geoFirestore.queryAtLocation(new GeoPoint(latitude, longitude), 100);
geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
@Override
public void onDocumentEntered(DocumentSnapshot documentSnapshot, GeoPoint geoPoint) {
stringIntegerMap=documentSnapshot.getData();
Query query=propertyRef.whereEqualTo("mID",Integer.parseInt(documentSnapshot.getId()));
dataFetch(query,R.id.discoverRV);
//here how i tried to print the result to see how many documents i got
for (Map.Entry<String,Object> entry : stringIntegerMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue().toString();
Toast.makeText(mContext,key+" "+value,Toast.LENGTH_LONG).show();
}
}
And here i build the query and send it to recyclerview adapter
private void dataFetch(Query query,int rvView){
FirestoreRecyclerOptions<Property> options = new FirestoreRecyclerOptions.Builder<Property>()
.setQuery(query, Property.class)
.build();
mAdapter = new DiscoverAdapter(options);
RecyclerView recyclerView = root.findViewById(rvView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
recyclerView.setAdapter(mAdapter);
mAdapter.startListening();
}