Skip to content

Limit Query #259

Description

@AfiqMutaz

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(() {});
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions