I am creating a tableView that will populate all nearby Users within 100km - then order by their HighScore.
The code that I am using is below...
let geoFireUser = GeoFire(firebaseRef: DBProvider.instance.gameHighScoreRef)
self.circleQuery = geoFireUser?.query(at: currentUserCLLocation, withRadius: 100)
circleQuery?.observe(.keyEntered, with: { (key, location) in
let queryRef = DBProvider.instance.gameHighScoreRef.queryOrdered(byChild: "highScore").queryLimited(toLast: 100)
queryRef.observe(.childAdded, with: { (snapshot) in
let userNearbyData = UserData(snapshot: snapshot)
self.listOfNearbyUsers.append(userNearbyData)
self.listOfNearbyUsers.sort(by: {$0.highScore > $1.highScore})
})
})
}
I have created a segmented control that will show, GLOBAL LIST and NEARBY LIST (100km).
Currently in my gameHighScoreRef - there are only 3 unique Keys (3 users). Also my Firebase structure looks like Root -> gameHighScore -> GeoFire, HighScore, UserName..
My GLOBAL LIST shows 3 users. My NEARBY LIST shows 9 users. It should only show 3 users.
To make sure that my class was working correctly, I then removed the geoFire CircleQuery and it showed 3 USERS.
How can I tweak my code to search for users within 100km. Then sort by their HighScore?
Any help would be greatly appreciated.