我对使用Firebase及其位置库GeoFire非常新颖。目前我在构建数据时遇到了一些问题。用户位置上的GeoFire查询
目前我的数据库是这样的:
users
facebook:xxxxx
displayName: xx
firstName: xx
lastName: xx
location:
g: xxxx
l:
0: xxx
1: xxx
facebook:yyyyy
displayName: yy
firstName: yy
lastName: yy
location:
g: yyyy
l:
0: yyy
1: yyy
我想在这附近登陆,我的当前用户的用户查询要做到这一点我不明白我有什么路径指定。
在我做这样的时刻(但不工作):
保存当前位置
let root = Firebase(url: "myapp.firebaseio.com")
let usersRoot = root.childByAppendingPath("users")
geoFire = GeoFire(firebaseRef: usersRoot.childByAppendingPath(root.authData.uid))
geoFire.setLocation(currentLocation, forKey: "location") { (error) in
if (error != nil) {
print("An error occured: \(error)")
} else {
print("Saved location successfully!")
}
}
获取其他用户近
let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("users"))
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius)
query.observeEventType(GFEventTypeKeyEntered, withBlock: {
(key: String!, location: CLLocation!) in
print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'")
self.userCount++
self.refreshUI()
})
个UPDATE
保存当前位置
let root = Firebase(url: "myapp.firebaseio.com")
geoFire = GeoFire(firebaseRef: root.childByAppendingPath("locations"))
geoFire.setLocation(currentLocation, forKey: root.authData.uid) { (error) in
if (error != nil) {
print("An error occured: \(error)")
} else {
print("Saved location successfully!")
}
}
获取其他用户近
let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("locations"))
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius)
query.observeEventType(GFEventTypeKeyEntered, withBlock: {
(key: String!, location: CLLocation!) in
print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'")
self.userCount++
self.refreshUI()
})
谢谢!我正在尝试,但仍然无法正常工作。我想这种方式(考虑到你的数据库结构): 让geoFire = GeoFire(firebaseRef:root.childByAppendingPath( “user_locations”)) 令查询= geoFire.queryAtLocation(currentLocation,withRadius:10) query.observeEventType(GFEventTypeKeyEntered, withBlock:{ (key:String !, location:CLLocation!) print(“+ + + + Key'\(key)'进入搜索区域,位于'\(location)'”) }) – giacavicchioli
已解决,设置查询中心时出现问题。谢谢。 – giacavicchioli
Firebase geofire-js:如何获取静态(固定)位置附近的按键列表:http://stackoverflow.com/questions/43632746/firebase-geofire-js-how-to-get-list-of-keys -of-附近逐staticfixed-位置 –