代码如下。我已经看到了所有先前询问的问题,他们犯了写错误参考或不使用Geofire.set方法设置geofire的错误。请帮助
private void georadius(final LatLng pickup)
{
//geo
DatabaseReference r2=root.child("Active_Drivers");
GeoFire mG=new GeoFire(r2);
GeoQuery m=mG.queryAtLocation(new GeoLocation(pickup.latitude,pickup.longitude),radius);
m.removeAllListeners();
m.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
if (driverfound==false) {
driverfound = true;
driverid = key;
driverlocation = new LatLng(location.latitude, location.longitude);
}
}
@Override
public void onKeyExited(String key) {
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
}
@Override
public void onGeoQueryReady() {
if (driverfound==false)
{
radius++;
georadius(pickup);
}
}
@Override
public void onGeoQueryError(DatabaseError error) {
}
});
}
我的JSON:
{
"Active_Drivers" : {
"LgEnzsB4y3g0tQZEnIMJRFnnREU2" : {
"location" : {
".priority" : "ttqwsbkq5d",
"g" : "ttqwsbkq5d",
"l" : [ 30.6762423, 76.85536 ]
}
}
},
"Customer Requests" : {
"nCz2Rlk2SafeTXWarBs4T8EiIdm2" : {
"location" : {
".priority" : "ttqwsbu1fy",
"g" : "ttqwsbu1fy",
"l" : [ 30.6782832, 76.8549792 ]
}
}
答案 0 :(得分:2)
您的数据结构与this示例不同:
{
"fish1" : {
"g" : "pns0h0mf2u",
"l" : [ -53.435719, 140.808716 ]
},
"fish2" : {
"g" : "u417k3dwub",
"l" : [ 56.83069, 1.94822 ]
},
"fish3" : {
"g" : "8m3rz3s480",
"l" : [ 30.902225, -166.66809 ]
}
}
每个孩子都有一个额外的location
级。我很确定Geofire在每个孩子的正下方寻找.priority
和g
。