可以从我当前的位置获取存储在firebase db中的所有GeoFire帖子的特定半径吗?
示例:如果进入我的数据库的节点,我有10个帖子,只有3个在我当前位置有效,半径为0.5公里,我将获得3个帖子。
这是我的DB的结构:
{
"posts" : {
"-L9qTBD1WPgF0h2ungz-" : {
"desc" : "lorem ipsum",
"isActive" : true,
"idGeofire" : "ID1GEOFIRE"
},
"-L9qTDImKE4HHgxH5YDs" : {
"desc" : "lorem ipsum",
"isActive" : true,
"idGeofire" : "ID2GEOFIRE"
}
},
"geofire" : {
"ID1GEOFIRE" : {
"IdPost" : "L9qTBD1WPgF0h2ungz",
"l" : {
"0" : 46.632347,
"1" : 3.6354347
}
},
"ID2GEOFIRE" : {
"IdPost" : "L9qTDImKE4HHgxH5YDs",
"l" : {
"0" : 25.6314647,
"1" : 50.6369447
}
},
}
}
答案 0 :(得分:1)
要获取某个位置范围内的节点,您需要use a geoquery,如文档中所示:
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);
然后,您将收到范围内节点的onKey...
个事件,例如对于每个帖子,您都会获得onKeyEntered
:
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); }