Swift 两个纬度之间的Firebase查询

Swift 两个纬度之间的Firebase查询,swift,firebase,firebase-realtime-database,Swift,Firebase,Firebase Realtime Database,我从数据库接收数据时遇到问题,其中帖子的纬度在用户当前纬度的+/-0.1范围内 我的Firebase树如下所示: { "person" : { "ss" : { "email" : "contact@surrogatesystems.com", "username" : "Surrogate Systems" }, "CZ6Ujxsm0SXybtcLBthXOpG3YgU2" : { "email" : "ljahnke9@gmail.com", "u

我从数据库接收数据时遇到问题,其中帖子的纬度在用户当前纬度的+/-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,即使我的系统中有符合条件的实体


我的电话出了什么问题,我该如何修复它?

我看到了同样的行为。我通过插入对queryOrderedByChild的调用来获得预期的结果:

    let query = ref.child("prayers")
                .queryOrderedByChild("latitude")
                .queryStartingAtValue(lat - 0.1)
                .queryEndingAtValue(lat + 0.1)
                .queryLimitedToFirst(50)
                .observeEventType(.ChildAdded, withBlock: { (snapshot) in
                    print(snapshot)
                })

我看到了同样的行为。我通过插入对queryOrderedByChild的调用来获得预期的结果:

    let query = ref.child("prayers")
                .queryOrderedByChild("latitude")
                .queryStartingAtValue(lat - 0.1)
                .queryEndingAtValue(lat + 0.1)
                .queryLimitedToFirst(50)
                .observeEventType(.ChildAdded, withBlock: { (snapshot) in
                    print(snapshot)
                })

您能从数据库中显示一些您希望与此查询匹配的实际JSON数据吗?通过单击“导出”按钮,您可以从Firebase数据库控制台轻松地获取该信息。Y将JSON作为文本使其具有可搜索性,使我们能够轻松地使用它来测试您的实际数据,并在我们的答案中使用它,一般来说,这是一件好事。您能否显示一些您希望与此查询匹配的数据库中的实际JSON数据?通过单击“导出”按钮,您可以从Firebase数据库控制台轻松地获取该信息。Y将JSON作为文本使其具有可搜索性,使我们能够轻松地使用它来测试您的实际数据,并在我们的答案中使用它,一般来说,这是一件好事。
observeEventType
对您来说是什么样的?我的是:
query.observeEventType(FIRDataEventType.Value,with block:{(snapshot)in
和我的
snapshot
null
将其添加到似乎有效的答案中,然而,
snapshot
只是一个祷告,分成6个键(祈祷的键)。我需要
snapshot
成为
[祈祷:键]
而不是
[Key:Value]
observeEventType
对您来说是什么样的?我的是:
query.observeEventType(FIRDataEventType.Value,with block:{(快照)在
中,我的快照为空将其添加到似乎有效的答案中,然而,
快照
只是一个祷告,分成6个键(祈祷的键)。我需要
快照
[祈祷:键]
而不是
[键:值]