secret secret - 3 months ago 60
Android Question

getting users on my radius via geofire to a list and rules

so to this points im facing 2 problems,
first one is


Using an unspecified index. Consider adding '".indexOn": "g"' at
Geofire to your security and Firebase Database rules for better
performance


while running the app
those are my securety rules via firebase

{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}


this is my databaseenter image description here

second question, im trying to get the number of users on my radius except me, for some reason , im finding only one eventhough on the database theres are 2 at the location , and radius is 100km, here example of the code, please help me

final Set<String> runnersNearby = new HashSet<String>();

geoFire.setLocation(uid, new GeoLocation(lat, lang));

GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, lang), radius);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Toast.makeText(UserProfile.this, "Successfully Found", Toast.LENGTH_SHORT).show();
if (key != user.getUid())
runnersNearby.add(key);
Log.d("Number of users", String.valueOf(runnersNearby.size()));
Log.d("KEY", String.valueOf(key));
}

@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();
}
});


thank you very much guys!

Answer

The message is pretty explicit:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",
    "Geofire": {
      ".indexOn": "g"
    }
  }
}
Comments