我正在尝试使用 查询离用户位置最近的geofirestore
文档,我的代码仅获取 1 个文档,正如您在代码中看到的,我将半径设置为 100 公里,并从同一位置设置文档的位置。
我试图snapshot
在地图中打印结果,它只打印 1 个文档
query
在这里,我发送文档 ID来构建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();
}
}
在这里我构建查询并将其发送到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();
}