-1

right now m using dataSnapshot.getChildrenCount but it only counts the node available in a child.

here is my code

 GeoFire geoFire = new GeoFire(ref.child("Userlocation"));
    GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), Raius);

    geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
        @Override
        public void onDataEntered(DataSnapshot dataSnapshot, GeoLocation location) {


            int userCounter = (int) dataSnapshot.getChildrenCount();
            ads5_userCounter.setText(userCounter + "");


        }

        @Override
        public void onDataExited(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onDataMoved(DataSnapshot dataSnapshot, GeoLocation location) {

        }

        @Override
        public void onDataChanged(DataSnapshot dataSnapshot, GeoLocation location) {

        }

        @Override
        public void onGeoQueryReady() {

        }

        @Override
        public void onGeoQueryError(DatabaseError error) {

        }
    });

this method is not counting all the user avilable at this location radius. please help.

sam
  • 216
  • 4
  • 17
  • Hi sam, can you explain more about your problem? for example you can share your firebase structure and show what exactly you need to get from it. – Vadim Eksler Oct 23 '18 at 05:43

1 Answers1

0

The onDataEntered method is called for each node that is within the range. Once onDataEntered has been called for all nodes that are initially in range, the onGeoQueryReady method is called. That means that you can increment a counter in onDataEntered and then show it in onGeoQueryReady.

long count = 0;
geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
  @Override
  public void onDataEntered(DataSnapshot dataSnapshot, GeoLocation location) {
    count++;
  }
  @Override
  public void onDataExited(DataSnapshot dataSnapshot) { }
  @Override
  public void onDataMoved(DataSnapshot dataSnapshot, GeoLocation location) { }
  @Override
  public void onDataChanged(DataSnapshot dataSnapshot, GeoLocation location) { }

  @Override
  public void onGeoQueryReady() {
    ads5_userCounter.setText(""+count);
  }

  @Override
  public void onGeoQueryError(DatabaseError error) {
    throw databaseError.toException(); // don't ignore errors
  }
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • thank you frank, i was thinkiing about that but if was looking for direct method. but thanks again. – sam Oct 24 '18 at 03:27