【发布时间】:2016-06-27 01:33:12
【问题描述】:
当帖子的纬度在用户当前纬度的 +/- 0.1 范围内时,我无法从我的数据库接收数据。
我的 Firebase 树如下:
{
"person" : {
"ss" : {
"email" : "contact@surrogatesystems.com",
"username" : "Surrogate Systems"
},
"CZ6Ujxsm0SXybtcLBthXOpG3YgU2" : {
"email" : "ljahnke9@gmail.com",
"username" : "Logan Jahnke"
}
},
"prayers" : {
"p0" : {
"contents" : "For understanding of Firebase as we build the Surge: Prayer Sharing application.",
"likes" : 100,
"personid" : "ss",
"posted" : "2016-06-21 20:15:00",
"latitude" : 33.9441737581188,
"longitude" : -83.3843067012304
},
"p1" : {
"contents" : "This is a test prayer.",
"likes" : 0,
"personid" : "CZ6Ujxsm0SXybtcLBthXOpG3YgU2",
"posted" : "2016-06-21 20:00:00",
"latitude" : 33.9441737581188,
"longitude" : -83.3843067012304
},
"p2" : {
"contents" : "My prayer request is that every child in Los Andes, Panama know the love of Jesus Christ. I also pray for their families and their friends. I pray that their education runs smoothly and that they learn the English they desire to know. I pray that we made an impact on them.",
"likes" : 0,
"personid" : "CZ6Ujxsm0SXybtcLBthXOpG3YgU2",
"posted" : "2016-06-21 20:00:00",
"latitude" : 35.3341737581184,
"longitude" : -81.3843067012304
}
} }
纬度和经度的类型为Double。我目前的查询是:
let lat = // user's latitude by using CLLocation -> ~33.9
let query = ref.child("prayers").queryStartingAtValue(lat - 0.1, childKey: "latitude").queryEndingAtValue(lat + 0.1, childKey: "latitude").queryLimitedToFirst(50)
// This should theoretically return a list of size 2
这会在调用快照时返回 NSNull,即使我的系统中有符合条件的整体。
我的电话出了什么问题,我该如何解决?
【问题讨论】:
-
您能否从您的数据库中显示一些您希望与此查询匹配的实际 JSON 数据?您可以通过单击导出按钮轻松地从 Firebase 数据库控制台获取它。 Y 将 JSON 作为文本使其可搜索,使我们能够轻松地使用它来测试您的实际数据并将其用于我们的答案中,通常只是一件好事。
标签: swift firebase firebase-realtime-database