在Swift中从Radius中检索GeoFire中的键

时间:2016-10-23 15:35:24

标签: swift firebase geolocation firebase-realtime-database geofire

我有以下Firebase数据库JSON数据结构:

{
  "Post List" : {
    "-KUlvg8mCEGfY5ZSKCou" : {
      "addedByUser" : "7llQbPdy2NV7aO337h7ap0qLOhC3",
      "content" : "Post1",
      "cost" : "$450",
      "duration" : "Daily",
      "latitude" : "25.0879721592719",
      "longitude" : "55.1487715855458",
      "number" : "01234567890",
      "timestamp" : "Posted on: Sun 23 Oct"
    }
  },
  "Post Locations" : {
    "-KUlvg8mCEGfY5ZSKCou" : {
      ".priority" : "thrnwznh58",
      "g" : "thrnwznh58",
      "l" : [ 25.0879721592719, 55.1487715855458 ]
    }
  },
  "User Locations" : {
    "7llQbPdy2NV7aO337h7ap0qLOhC3" : {
      ".priority" : "thrnwypqu9",
      "g" : "thrnwypqu9",
      "l" : [ 25.0829547120321, 55.1505315855337 ]
    }
  }
}

我希望有一个GeoFire查询,它将返回半径为1KM内的所有密钥[FIRAutoID' s],例如"用户位置"这些帖子是静态的,一旦设置了用户位置,它也将被修复。从半径查询结果我期望返回" -KUlvg8mCEGfY5ZSKCou"所以我可以参考帖子详细信息。希望这是有道理的。非常感谢,D.不能在网上找到很多关于GeoFire的内容......看起来还处于初期阶段?...

1 个答案:

答案 0 :(得分:4)

想出来

func geoFireQuery() {

        let circleQuery = geoFire.query(at: self.myLocation, withRadius: 0.5)

        _ = circleQuery!.observe(.keyEntered, with: { (key: String?, location: CLLocation?) in

        print (key!)

    })

    circleQuery?.observeReady({
        print("All initial data has been loaded and events have been fired!")

    })

}

这似乎给了我我需要的东西。现在将这些键引用到FBDB的其他部分。 :)