在通过 firebase Git 工作后,我遇到了一些问题,这是我的数据库:
一开始我定义
geoFire.setLocation("firebase-hq", new GeoLocation(lat, lang));
编辑:经过几次修复,我发现了这个问题......我试图找到某个用户中的所有用户,经过一些修复它确实找到了每个人,但它也发现了自己......我怎样才能避免添加我的自己的用户(或从找到的用户中删除我自己的用户密钥......)这是代码(希望能更好地解释这个问题,因为英语不是我的母语)。 runnersNearby 是此半径上的用户...
mDatabase = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
double lat = gpsTracker.getLatitude();
double lang = gpsTracker.getLongitude();
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("latitude").setValue(lat);
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("longitude").setValue(lang);
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("Availability").setValue(true);
geoFire.setLocation(uid, new GeoLocation(lat, lang));
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, lang), 100);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Toast.makeText(UserProfile.this, "Successfully Found", Toast.LENGTH_SHORT).show();
runnersNearby.add(key);
Log.d("Number of users", String.valueOf(runnersNearby.size()));
Toast.makeText(UserProfile.this, String.valueOf(runnersNearby.size()), Toast.LENGTH_SHORT).show();
}
@Override
public void onKeyExited(String key) {
Toast.makeText(UserProfile.this, "left the place", Toast.LENGTH_SHORT).show();
runnersNearby.remove(key);
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
Toast.makeText(UserProfile.this, "key moved but here", Toast.LENGTH_SHORT).show();
}
@Override
public void onGeoQueryReady() {
System.out.println("All initial data has been loaded and events have been fired!");
}
@Override
public void onGeoQueryError(DatabaseError error) {
Toast.makeText(UserProfile.this, "Error Occured", Toast.LENGTH_SHORT).show();
}