Not getting expected results from Firestore with geoflutterfire

Viewed 75

I am using the geoflutterfire package to implement a nearby list but it always not return very near places.

I don't know if i have something wrong in my code or this package has issues.

First of all: i created two docs as a test, every doc has difference position with some meters as distance between them.

Gere is set data to Firestore:

Position position =  await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);

    final geo = Geoflutterfire();

    GeoFirePoint myLocation = geo.point(latitude: position.latitude, longitude: 
    position.longitude);

    FirebaseFirestore.instance.collection( "location").doc('testUser1').update({
      'position': myLocation.data,
      'latitude':myLocation.latitude,
      'longitude': myLocation.longitude,
    });

Note: i also created doc for testuser2.

Here i need to see results:

Future getNearDistanceForTest()async{

    final geo =  Geoflutterfire();

    //this my lati-longi as a test user1
    GeoFirePoint? center = geo.point(latitude: currentUser.latitude!, longitude: 
    currentUser.latitude!);

    var collectionReference = FirebaseFirestore.instance.collection('location');

    double radius = 20; // here i am trying to get only 20km as a distance even though the distance is not more then 10 meters between test user1 and 2
    String field = 'position';

  await  geo.collection(collectionRef: collectionReference)
        .within(center: center, radius: radius, field: field, strictMode: true).forEach((element) {

    print(element.length); // output 0

  });
}   

As shown in example the output is 0, but when i increase the radius to a high for example to 500.

So finally the output is 1 , even though the distance is closer than that mush of radius.

Does anyone know/see why that happens?

0 Answers
Related