I want to find nearest users to my location. (For example up to 5km) My nodes in firebase database like below structure,
+ users
+ user_id0
- latitude: _
- longitude: _
Is there any way getting exact users in that radius. Otherwise I should check each user of them nearest position or not to me using CLLocation distance method.
I'd highly recommend using Geofire for something like this.
To set it up, your data structure will slightly change. You can still store lat/lng on your users, but you will also create a new Firebase table called something like
users_locationsYour
users_locationstable will be populated through Geofire, and will look something like thisIn general, this is how you would store a location in Geofire, but you can set it up to save whenever your user object is created / updates location.
When you've saved your locations in
users_locations, you can then use aGFQueryto query for all the users in a certain range.