suiko1984 / geofirestore-android

GeoFire for Android - Realtime location queries with Firebase Cloud Firestore
13 stars 4 forks source link

GeoFirestore Queries Results Order #3

Closed KelvinPac closed 4 years ago

KelvinPac commented 5 years ago

Hi, thanks for this awesome library. While working with the new version I realized the results of the query GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 10); are ordered in no specific manner I would come to think of. I expected the results would be ordered in ASC or DESC order based on the radius used and the document location. What's your take on this @suiko1984 or how does the implementation work?

suiko1984 commented 4 years ago

The algorithm used for geoquerying the data does not allow to order them by distance. What you can do is retrieve the unsorted results. In the callback, order them by distance using Location.distanceTo(...) https://developer.android.com/reference/android/location/Location#distanceTo(android.location.Location)

KelvinPac commented 4 years ago

@suiko1984 When using this behaviour that doesn't allow order by distance, what happens when the radius is maybe 20KM and I have 100 items within that radius, but I limit the results to only 5. Will I get the nearest 5 or just random 5 that might not be the nearest ones?