【发布时间】:2019-03-25 06:24:30
【问题描述】:
我想使用 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) {
}
});
此查询未获取数据。
这是我的数据库结构
这是我的 Firebase 安全规则
{"rules": {
".read": "auth != null",
".write": "auth != null"}}
我是否需要更改 firebase 安全规则才能使用 geofire?
请帮帮我!
【问题讨论】:
-
我们无法知道
GeoFire geoFire = new GeoFire(ref.child("businesLocation").child(shop_categoryName).child(shop_sub_categoryName))是否指向您在屏幕截图中显示的数据。请尝试在一个孤立的、最小的数据结构中重现该问题。我强烈建议阅读how to create a minimal, complete, verifiable example 了解为什么以及如何这样做.. -
@FrankvanPuffelen 我刚刚添加了更多空间信息。请看一下
-
变量 Education 和 CoachingCenter 代表什么?您是否尝试打印路径以确保其有效?同样,location 和 Raius 是什么?如果不理解和验证这些信息,我们只会猜测答案。
-
您的安全规则
".read": "auth != null"意味着user must be authenticated 能够读取任何数据。如果不是,您会在onGeoQueryError中收到错误,您现在将忽略该错误。将其实现为public void onGeoQueryError(DatabaseError error) { throw error.toException(); }以在这种情况下获得更明确的错误。另见stackoverflow.com/questions/37403747/firebase-permission-denied/… -
但用户已通过身份验证。它仍然没有增加数据。那么在这种情况下我该如何找到解决方案
标签: android firebase firebase-realtime-database geofire