1

I want to retrieve data from a firebase database with geofire location query but its just trigring onGeoQueryReady instead of onKeyEntered.

I'm setting my location like this

user = auth.getCurrentUser().getUid();
 GeoFire geoFire = new GeoFire(ref.child("businesLocation").child(Education).child(CoachingCenter));



 geoFire.setLocation(user, new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {
                @Override
                public void onComplete(String key, DatabaseError error) {




                }
            });




        }
    });

and retriving data like this

GeoFire geoFire = new GeoFire(ref.child("businesLocation").child(Education).child(CoachingCenter));
GeoQuery geoQuery = geoFire.queryAtLocation((location), Raius);

geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            getShoplist(key);
        }

        @Override
        public void onKeyExited(String key) {
            getShoplist(key);
        }

        @Override
        public void onKeyMoved(String key, GeoLocation location) {
        }

        @Override
        public void onGeoQueryReady() {
        }

        @Override
        public void onGeoQueryError(DatabaseError error) {
        }
    });

This query is not getting the data.

Here is my database structure

enter image description here

Here are my firebase security rules

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

Do I need to change the firebase security rules for using geofire?

Please help me out!

sam
  • 216
  • 4
  • 17
  • 1
    We have no way to know if `GeoFire geoFire = new GeoFire(ref.child("businesLocation").child(shop_categoryName).child(shop_sub_categoryName))` is pointing to the data you show in the screenshot. Please try to reproduce the problem in an isolated, minimal data structure. I highly recommend reading [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) to learn why and how to do that.. – Frank van Puffelen Oct 20 '18 at 17:08
  • @FrankvanPuffelen i have just added more spacific infromation. please have a look – sam Oct 21 '18 at 03:18
  • 1
    What do the vars *Education* and *CoachingCenter* represent? Did you try printing the path to ensure its valid? Along those same lines, what is *location* and *Raius*? Without understanding and verifying that information, we would just be guessing at an answer. – Jay Oct 21 '18 at 12:58
  • Your security rule `".read": "auth != null"` means that a [user must be authenticated](https://firebase.google.com/docs/auth/) to be able to read any data. If they're not you get an error in `onGeoQueryError`, which you're now ignoring. Implement that as `public void onGeoQueryError(DatabaseError error) { throw error.toException(); }` to get a more explicit error in that case. Also see https://stackoverflow.com/questions/37403747/firebase-permission-denied/37404116?noredirect=1#comment92734422_37404116 – Frank van Puffelen Oct 21 '18 at 14:00
  • but user is authenticated. and its still not fatching the data. so how can i find the solution in this situation – sam Oct 21 '18 at 16:41
  • @FrankvanPuffelen onKeyEntered is not trigring it just trigring onGeoQueryReady , why?? – sam Oct 22 '18 at 06:31
  • That means that there are no results in the database location you're querying for the range you're querying for. It's impossible for us to say why that is, because we don't know the values of `location` and `Raius`. Try reproducing the problem with hard-coded values, then update the question with those. – Frank van Puffelen Oct 22 '18 at 13:06
  • now its working i change the security rules and now its fatching the data easily – sam Oct 23 '18 at 03:27

1 Answers1

2

After changing my database security rules it starts working

 {
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",
    "geofire": {
      ".read": "true",
        ".indexOn": ["g"]
      }
    } 
}

it starts fetching the data now.:)

xaif
  • 553
  • 6
  • 27
sam
  • 216
  • 4
  • 17