fluttercommunity / firestore_helpers

Firestore Helpers - Firestore helper function to create dynamic and location based queries. Maintainer: @escamoteur
https://pub.dev/packages/firestore_helpers
MIT License
48 stars 19 forks source link

radiusInKilometers 120.0km returns 400.0 km location #8

Closed ghost closed 5 years ago

ghost commented 5 years ago

I'm trying to fetch document inside circle of 120.0 km. But it returns 400.0 km away. Is this a bug or I'm making some mistake?

This is Osaka Abeno.

   var lat = 34.643839; 
   var lng = 135.512383;
   var area = GeoPoint(lat, lng);

This is Tokyo Station.

   var lat = 35.681167; 
   var lng = 139.767052;
   var area = GeoPoint(lat, lng);

I searched these distance in google map and it returns over 400 km. I fetched like so.

Stream<List<Items>> itemsStream() {
    return getDataInArea(
    area: Area(area, 120.0), 
    source: Firestore.instance.collection('items'), 
      locationFieldNameInDB: 'location', 
      mapper: (document) {
        print(document.data);
      },
    );
  }
escamoteur commented 5 years ago

Hmm that is strange. Will check it tomorrow

ghost commented 5 years ago

Thank you. I appreciate it.

ghost commented 5 years ago

I don’t mean to rush but do you have any update?

escamoteur commented 5 years ago

What value does aera have?

ghost commented 5 years ago

Sorry for late response I didn't get email notification somehow. area is Osaka Abeno. I set iPhone simulator's current location to Osaka Abeno. But it returns Tokyo which is 400km away.

escamoteur commented 5 years ago

Hi,

I created a little example project in this repo now:

image

with 410km radius I get both cities back if I change it to 400 only Tokyo

image

I also tried 120km and I don't get Osaka. The same if I set the current position to Osaka, I don't see Tokyo with an radius of <410km

ghost commented 5 years ago

HI, sorry again. I tried that again but still return Tokyo. Could you share your code? I hate to say but could you run this code? This is exactly the same code that I ran.

 final GeoPoint location = GeoPoint(34.649252, 135.539863);
 final Area area = Area(location, 120.0);
 return getDataInArea(
    area: area,
    source: Firestore.instance.collection('helper'), 
      locationFieldNameInDB: 'location', 
      mapper: (document) {
        print(document.data);
       // return 
       // flutter: {name: Tennoji Station, location: Instance of 'GeoPoint'}
      // flutter: {name: Osaka Station, location: Instance of 'GeoPoint'} 
      // flutter: {name: Tokyo Station, location: Instance of 'GeoPoint'}
      },
    );
  }

And this my Firestore data looks like. 2018-11-04 9 46 52 2018-11-04 9 47 03 2018-11-04 9 47 20

I'm sorry but hope you could help. Thank you so much.

escamoteur commented 5 years ago

Hi,

the code is in the example project of this repository I have honestly no idea why it does not work for you. Your code looks like mine

ghost commented 5 years ago

Thank you for replying. Yeah it's weird. Thanks anyway I'll figure it out somehow!