DarshanGowda0 / GeoFlutterFire

:fire:GeoFlutterFire:fire: is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://youtu.be/MYHVyl-juUk
MIT License
305 stars 261 forks source link

Clarification on Radius #131

Open tapizquent opened 3 years ago

tapizquent commented 3 years ago

While testing the .within method, I realized that the radius property does not seem to be in Km as stated in the example project.

I base this statement because I have a document in my database of the following structure:

locations : {
    my_location_id : {
        name : locationName,
        position : {
            geohash: djn6c055s,
            geopoint: {
                latitude: 26.628408,
                longitude: -81.874084
            }
        }
    }
}

As can be seen, the LatLng is (26.628408, -81.874084)

When calling the method:

I am using:

final center = geoflutterfire.point(latitude: 26.628420, longitude: -81.804004);

geoflutterfire
        .collection(collectionRef: collection)
        .within(
            center: center,
            radius: 50,
            field: 'position',
            strictMode: true)

If you use a tool such as https://www.nhc.noaa.gov/gccalc.shtml, you can see that the there is approximately only 7km between these points, but even with radius 50, GeoFlutterFire returns 0 items.

Increasing the radius to 200 does return the correct item.

Thus, I am led to believe that the radius is indeed not in km.

I would like to get some more details on this and correct the documentation if that is the case.

Beautylivery commented 3 years ago

i get completely weird results ... with 3 data points all in an area of 3 km i can not really filter for the ones in a 1km range only to 2 points .... i even get the far away point of 3 km but missing one close point of <1km i am let to believe that the within function also have troubles here.

awaik commented 3 years ago

Will check it next week. Thank you!

kamaleshbasu commented 3 years ago

The plugin makes use of GeoHashes. The problem with GeoHash based queries can be summarised as:

Geohashing guarantees that the longer a shared prefix between two geohashes is, the spatially closer they are together. The reverse of this is not guaranteed, as two points can be very close but have a short or no shared prefix.

There is a possibility that the problem is due to boundary issues between two edge case geohashes. https://en.wikipedia.org/wiki/Geohash

jack84156 commented 2 years ago

same here . in my case it always return item 0 if distance was less than 100 . so i when i increase radius to 500 so it returns results ,even though after hard tested i realized the problem was from .within method and not only radius because i am sure this plugin uses native geo hash wrapping to flutter , i am use the same geo hash native in my java app , and there no issues into it and it can have a very accurate vision with distance , i hope this package solve it's issues

jlopezrod commented 2 years ago

same here. I've used the next code:

print('${list.length} close'); list.forEach((element) { final point = GeoFirePoint(actualLatLng.latitude, actualLatLng.longitude); print( 'Distance from ${element.name}: ${point.distance(lat: element.latitude, lng: element.longitude)} kms'); });

it show me: 14.069 kms when my radius 'within' was 10.

.within(center: center, radius: 10, field: 'localization')