android - Geofire 正在触发 onGeoQueryReady 而不是 onKeyEntered

标签 android firebase firebase-realtime-database geofire

我想使用 geofire 位置查询从 firebase 数据库中检索数据,但它只是触发 onGeoQueryReady 而不是 onKeyEntered。

我正在这样设置我的位置

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) {




                }
            });




        }
    });

像这样检索数据

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) {
        }
    });

此查询未获取数据。

这是我的数据库结构

enter image description here

这是我的 firebase 安全规则

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

使用 geofire 是否需要更改 Firebase 安全规则?

请帮帮我!

最佳答案

更改我的数据库安全规则后它开始工作

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

它现在开始获取数据。:)

关于android - Geofire 正在触发 onGeoQueryReady 而不是 onKeyEntered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52907973/

相关文章:

Android 设计支持库可扩展的 float 操作按钮(FAB)菜单

java - ZXing on Android PDF417

swift - 如何在 Swift 中使用异步循环创建函数?

swift - 无法在 Firebase 数据库中合并两个 firebase 数组

ios - 在后台 Swift 中发送用户的位置

java - 尝试在回收 View 中显示用户信息 - Firebase

java - 如何通过单击按钮打开下载文件夹?

Android 传递依赖

android - FirebaseUI 身份验证错误 :Failed to resolve: com. android.support :xxx:26. 0.1

firebase - 云函数 : zip multiple documents from Cloud Storage