我正在尝试使用geofirestore
查询最接近用户位置的文档,我的代码仅提取1个文档,并且如代码中所见,我将半径设置为100km,并设置了半径来自同一位置的文档。
我试图在地图上打印snapshot
结果,并且仅打印1个文档
在这里,我发送文档ID以将query
内置到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();
}
答案 0 :(得分:0)
我认为您正在使用com.github.imperiumlabs:GeoFirestore-Android
,对吧?
从v1.5.0版本开始,代码和文档之间存在差异。该文档指出queryAtLocation
使用公里:
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
val geoQuery = geoFirestore.queryAtLocation(GeoPoint(37.7832, -122.4056), 0.6)
但是,代码将从米转换为纬度:
fun distanceToLatitudeDegrees(distance: Double) = distance / Constants.METERS_PER_DEGREE_LATITUDE
Github上有一个open issue。
将仪表传递到queryAtLocation应该可以解决问题。