Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Query #259

Open
AfiqMutaz opened this issue Dec 11, 2024 · 0 comments
Open

Limit Query #259

AfiqMutaz opened this issue Dec 11, 2024 · 0 comments

Comments

@AfiqMutaz
Copy link

I'm glad to see geoflutterfire continuing to be supported by the community! I'm simply trying to limit my query to 3 Firebase documents but it's still not limiting as expected.

void _testFetchUserNavigation(LatLng point) async {
    GeoPoint geopoint = GeoPoint(point.latitude, point.longitude);
    final GeoFirePoint center = GeoFirePoint(geopoint);
    const double radiusInKm = 1.0;
    const String field = 'geo';

    CollectionReference<Map<String, dynamic>> bsColRef =
        FirebaseFirestore.instance.collection('temp_stops');

    GeoPoint geopointFrom(Map<String, dynamic> data) =>
        (data['geo'] as Map<String, dynamic>)['geopoint'] as GeoPoint;

    final List<GeoDocumentSnapshot<Map<String, dynamic>>> stops =
        await GeoCollectionReference<Map<String, dynamic>>(bsColRef)
            .fetchWithinWithDistance(
      center: center,
      radiusInKm: radiusInKm,
      field: field,
      geopointFrom: geopointFrom,
      queryBuilder: (query) => query.limit(3),
    );

    stopsId = stops
        .map((stop) => {
              'stopId': stop.documentSnapshot.id,
              'distance': stop.distanceFromCenterInKm
            })
        .toList();
    setState(() {});
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant