我正在使用地理查询,以便在输入其他设备的区域时将数据上传到Firebase数据库。问题是离开区域时onKeyExited无效(onKeyEntered仅在第一次使用,如果再次进入该区域则无效)。 GeoQueryEventListener是否不会自动更新?
有什么想法吗?
final DatabaseReference drivers = FirebaseDatabase.getInstance().getReference(pickup);
GeoFire gfDrivers = new GeoFire(drivers);
final GeoQuery geoQuery = gfDrivers.queryAtLocation(new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), radius);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
if (!DriverFound) {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference tokens = db.getReference();
Token token = new Token(FirebaseInstanceId.getInstance().getToken());
tokens.child("TokensC").child(key).child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(token);
keyp= key;
DriverFound = true;
}
}
@Override
public void onKeyExited(String key) {
DriverFound = false;
DatabaseReference PaasajeroFinded = FirebaseDatabase.getInstance().getReference().child("TokensC").child(key).child(FirebaseAuth.getInstance().getCurrentUser().getUid());
PaasajeroFinded.removeValue();
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
}
@Override
public void onGeoQueryReady() {
if (!DriverFound && radius < LIMIT) {
geoQuery.removeAllListeners();
if (keyp != null)
{
DatabaseReference PaasajeroFinded = FirebaseDatabase.getInstance().getReference().child("TokensC").child(macumba).child(FirebaseAuth.getInstance().getCurrentUser().getUid());
PaasajeroFinded.removeValue();
}
}
}
@Override
public void onGeoQueryError(DatabaseError error) {
}
});