Giter VIP home page Giter VIP logo

Comments (4)

gohil-rahul-tft avatar gohil-rahul-tft commented on July 27, 2024 1

@kosukesaigusa Apologies from my side, you are right, I tested my code again and found that issue is in my code.

Firestore has limitation on whereIn upto 30 records.

final List<Stores> nearbyStores = await getNearbyStores(
        radius: radius,
        firestore: fireStore,
        userLocation: GeoPoint(20.68016662, -103.3822084),
      );

      try {

        // StoreRef Array to Fetch the products in a batched read
        final List<DocumentReference> storeRefs = nearbyStores
            .map((store) => fireStore
                .collection(StoreConstant.storeCollection)
                .doc(store.id))
            .toList();

        // Fetch all store products that meet the conditions
        final QuerySnapshot storeProductsSnapshot = await fireStore
            .collection('products_mvp')
            .where('is_exist', isEqualTo: true)
            .where('storeRef', whereIn: storeRefs)
            .get();

 catch (e) {
        print("STORE ERROR = $e");
      }    
      ```
      
 And thank you for the quick response. :)

from geoflutterfire_plus.

kosukesaigusa avatar kosukesaigusa commented on July 27, 2024

Thank you for creating an issue @gohil-rahul-tft!

I checked your code above, and the part you are using geoflutterfire_plus geo query is here:

final result =
          await GeoCollectionReference(locationCollectionRef).fetchWithin(
  center: center,
  radiusInKm: 6,
  field: 'geo',
  strictMode: true,
  geopointFrom: geopointFrom,
);

and seems nothing is wrong.

I also tried to reproduce the error you report

I/flutter (15285): (value as Iterable).length <= 30': 'in' filters support a maximum of 30 elements in the value [Iterable].

with the following code:

class GeoflutterfirePlusSample extends StatelessWidget {
  const GeoflutterfirePlusSample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        children: [
          ListTile(
            leading: const Icon(Icons.map),
            title: const Text('Call fetchWithin method'),
            onTap: () async {
              final locationCollectionRef =
                  FirebaseFirestore.instance.collection('locations');
              const center = GeoFirePoint(GeoPoint(35.681236, 139.767125));
              final result = await GeoCollectionReference(locationCollectionRef)
                  .fetchWithin(
                center: center,
                radiusInKm: 6,
                field: 'geo',
                strictMode: true,
                geopointFrom: (data) => (data['geo']
                    as Map<String, dynamic>)['geopoint'] as GeoPoint,
              );
              print(result);
            },
          ),
        ],
      ),
    );
  }
}

but it just returns normal result List<DocumentSnapshot<Map<String, dynamic>>> without errors.

If you get a minimal reproducible code (your code above still seems to include some geofluttefire_plus unrelated codes) of the problem, please reply here and share it!

from geoflutterfire_plus.

gohil-rahul-tft avatar gohil-rahul-tft commented on July 27, 2024

@kosukesaigusa The problem occurs when we have multiple locations or results nearby within a 6 KM radius. In my case, I was having 30+ results and that's why this problem occurred.

from geoflutterfire_plus.

kosukesaigusa avatar kosukesaigusa commented on July 27, 2024

@gohil-rahul-tft Thank you for your reply!

For example, I added 50 near locations from the center point like the following FloatingActionButton.onPressed, and called fetchWithin by tapping the ListTile, 50 results are successfully returned without errors.

/// geoflutterfire_plus パッケージの動作確認用 Widget.
class GeoflutterfirePlusSample extends StatelessWidget {
  const GeoflutterfirePlusSample({super.key});

  static const _latitude = 35.681236;

  static const _longitude = 139.767125;

  static final _locationsCollectionReference =
      FirebaseFirestore.instance.collection('sampleLocations');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        children: [
          ListTile(
            leading: const Icon(Icons.map),
            title: const Text('Call fetchWithin method'),
            onTap: () async {
              const center = GeoFirePoint(GeoPoint(_latitude, _longitude));
              final result =
                  await GeoCollectionReference(_locationsCollectionReference)
                      .fetchWithin(
                center: center,
                radiusInKm: 6,
                field: 'geo',
                strictMode: true,
                geopointFrom: (data) => (data['geo']
                    as Map<String, dynamic>)['geopoint'] as GeoPoint,
              );
              // output: 50
              debugPrint(result.length.toString());
            },
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          for (var i = 0; i < 50; i++) {
            final newLatitude = _latitude + i * 0.0001;
            final newLongitude = _longitude + i * 0.0001;
            final newGeoFirePoint =
                GeoFirePoint(GeoPoint(newLatitude, newLongitude));
            _locationsCollectionReference.add(<String, dynamic>{
              'geo': <String, dynamic>{
                'geopoint': newGeoFirePoint.geopoint,
                'geohash': newGeoFirePoint.geohash,
              },
            });
          }
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}

I think there are no in or array-contains query in geoflutterfire_plus package, so the error might occur from your own code not from geoflutterfire_plus?

I would like you to check your own code, or share the minimal reproducible example code please!

from geoflutterfire_plus.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.