本文介绍了用户位置上的GeoFire查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 与Firebase及其位置库GeoFire相比,我很新。目前我在构建数据时遇到了一些问题。 目前我的db是这样的: 用户脸书:xxxxx 显示名称:xx 姓氏:xx 姓氏:xx 位置:g :xxxx 0:xxx 1:xxx facebook:yyyyy displayName:yy 姓氏:yy 姓氏:yy 位置:g:yyyy l: 0:yyy 1:yyy 我想查询当前用户已经登录的用户。为此,我无法理解必须指定的路径。 目前我正在做这样的工作(但是这样做不行): 保存当前位置 let root = Firebase(url:myapp.firebaseio.com) let usersRoot = root.childByAppendingPath(users ) geoFire = GeoFire(firebaseRef:us $ geoFire.setLocation(currentLocation,forKey:location $ b print(发生错误:\(error))} else { print(保存位置成功!)} } 检索附近的其他用户 let let geoFire.queryAtLocation(currentLocation, withRadius:radius) $ b $ {$ b $(key:String !,位置:CLLocation!)中的query.observeEventType(GFEventTypeKeyEntered,withBlock: + +键'\(key)'进入搜索区域并位于位置'\(位置)') self.userCount ++ self.refreshUI()}) 更新 保存当前位置 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(发生错误:\(error))} else { print(保存位置成功!)} } 检索靠近的其他用户 let geoFire = GeoFire(firebaseRef:Firebase(url:myapp.firebaseio.com)。childByAppendingPath(locations)) let query = geoFire.queryAtLocation (currentLocation,withRadius:radius) $ b $(b:key:String !,位置:CLLocation!)的query.observeEventType(GFEventTypeKeyEntered,withBlock: + + + +键'\(键)'进入搜索区域并位于位置'\(位置)') self.userCount ++ self.refreshUI() }) 解决方案对于GeoFire,您必须在树中保留一段只包含地理位置,然后在树中包含有关项目的其他信息的另一个段。 user_locations uid1:g:xxxx l: 0:xxx 1:xxx uid2:g:xxxx l: 0 :xxx 1:xxx user_profiles: uid1: name:giacavicchioli uid2:名称:Frank van Puffelen 另请参阅:查询与GeoFire链接的Firebase数据 I'm quite new to work with Firebase and its location library, GeoFire. Currently I'm facing some problem when structuring my data.At the moment my db is something like this: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: yyyI would like to query on users that are near my current user logged in. To do so I can't understand what path I have to specify.At the moment I'm doing like this (but that doesn't work):saving current locationlet 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!") }}retrieving other users nearlet 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()})UPDATEsaving current locationlet 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!") }}retrieving other users nearlet 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()}) 解决方案 For GeoFire you must keep a segment in the tree that contains just the geolocation and then you have another segment in the tree that contains the other information about the items.user_locations uid1: g: xxxx l: 0: xxx 1: xxx uid2: g: xxxx l: 0: xxx 1: xxxuser_profiles: uid1: name: "giacavicchioli" uid2: name: "Frank van Puffelen"Also see: Query firebase data linked to GeoFire 这篇关于用户位置上的GeoFire查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 02:23