我的位置节点(LOCATION_REF)看起来像这样:( TuJ3J ...是userId)
我在附近搜索用户中的代码是:
func fetchUsers(){
LOCATION_REF.observeSingleEvent(of: .value, with: { (snapshot) in
let usersnap = snapshot.value as! [String : AnyObject]
for(_, value) in usersnap{
if let userid = value["uid"] as? String{
if userid == Auth.auth().currentUser?.uid{
self.currentLocation = CLLocation(latitude: value["latitude"] as! Double, longitude: value["longitude"] as! Double)
print(self.currentLocation)
}
}
}
})
fetchNearbyFriends()
}
func fetchNearbyFriends(){
LOCATION_REF.observeSingleEvent(of: .value, with: { (snapshot) in
let usersnap = snapshot.value as! [String : AnyObject]
for(_, value) in usersnap{
if let userid = value["uid"] as? String{
print(self.others.count) // got 0 when testing
for element in 0..<self.others.count{
if userid == self.others[element]{
let lat = value["latitude"] as? Double
let long = value["longitude"] as? Double
let title = value["placemark"] as? String
let loc = CLLocation(latitude: lat!, longitude: long!)
let distance = self.currentLocation.distance(from: loc)
let newFriendObject = Location(distance: distance, location: loc, locTitle: title!)
self.nearByFriendsDetailsArray.append(newFriendObject)
self.distances.append(distance)
}
}
}
}
//... ...
})
}
有人可以为我指明如何从Firebase获取附近用户的方向吗?我有一个存储所有用户信息的用户节点,还有一个位置节点(请参见上图)。我想根据位置节点中的结果从用户节点中获取用户。我曾经见过有人在使用Geofire,但是该吊舱不再活动。