mbramwell1 / GeoFire-Android

Query Firestore documents using GeoLocation coordinates.
Apache License 2.0
21 stars 0 forks source link

.whereNearTo working only if collection has a limited number of items #21

Open ferakles-dev opened 4 years ago

ferakles-dev commented 4 years ago

Testing the library: when querying a collection that contains 20 documents, the query returns the expected results. However, in case of big collections (>10k documents), the query is not returning the expected results. For example, I have around 30 documents within the radius of 1 km, and around 10000 documents outside such a radius. When querying documents within a radius of 1 km and a limit of 30 documents:

QueryLocation queryLocation = QueryLocation.fromDegrees(location.getLatitude(), location.getLongitude());
Distance searchDistance = new Distance(1, DistanceUnit.KILOMETERS);

geoFireQuery = geoFire.query()
    .whereNearTo(queryLocation, searchDistance)
    .limit(30)
    .build();

the first 28 results have a distance of 900 m - 10 km, and the remaining 2 have a distance of 129.5 km. 90% of the documents within radius of 1 km are not returned unfortunately.

If I remove the limit, the query returns 1100 documents... Of course most of them are well outside the radius. For information, I inserted the geoFireLocation field in each document via Javascript, using the formula: degreeMatch = (latitude+90)*180 + longitude;