imperiumlabs / GeoFirestore-Android

GeoFirestore for Android - Realtime location queries with Firestore
MIT License
123 stars 36 forks source link

getAtLocation doesn't work #37

Open ntripathy opened 5 years ago

ntripathy commented 5 years ago

I am not getting desired result when I pass a radius other than 0. When I pass the radius as 0 then I get all the documents returned.

Here is my code snippet in. Android using Java

GeoFirestore gfs = new GeoFirestore(cr) gfs.getAtLocation(new GeoPoint(latitude, longitude), 0, new GeoFirestore.SingleGeoQueryDataEventCallback() { @Override public void onComplete(List<? extends DocumentSnapshot> list, Exception e) { Log.d(TAG, "Documents matched:" + list.size()); // When radius is 0 then it returns all the documents otherwise it is empty list. } });

ntripathy commented 5 years ago

I think the radius is in meters and not in Kilometers. So when I give larger values then it is matching and returning desired documents.

CaelumF commented 5 years ago

But the doc says it's in km? I can't see what I should when assuming km either so I reckon this should be opened and is probably a doc issue

Supercaly commented 5 years ago

I've given a rough look at the code and I think the error is that the radius is not converted from Km to m (internally it uses meters), so you're definitely right to reopen this issue and I'll mark this as a bug.

jonbhanson commented 4 years ago

I have confirmed that the library does indeed use meters although the documentation states kilometers.

in GeoHashQuery.kt, the bitsForBoundingBox routine call GeoUtils.distanceToLatitudeDegrees(size) to convert the length to degrees latitude. Here is the code from that function:

fun distanceToLatitudeDegrees(distance: Double) = distance / Constants.METERS_PER_DEGREE_LATITUDE

Workaround: pass meters to the queries instead of kilometers.

ameerhamza6733 commented 4 years ago

From initial testing i am sure it is not in KM, if you pass distance in KM then it calculates GEO hash for query upto 8 char, but if you pass distance in meters then it calculates GEO hash boundary box upto 5 char which make more sense