Skip to content

Locations only appear when the radius is set to a large value #230

Description

@FabioCFonseca

I'm running this query, but it only returns the nearby locations when I set the radiusInKm to a very large number (1500).

Anything below that doesn't return anything, even though there are nearby locations.

What could be causing this?

Stream<Either<Exception, Set<location>>> watchlocations(
    UserGeopoint userPosition,
  ) {
    const radiusInKm = 25;
    final collectionRef =
        _firestore.locationCollection().withConverter<Either<Exception, location>>(
              fromFirestore: locationFirestoreHelpers.locationFromFirestore,
              toFirestore: (_, __) => {},
            );

    return GeoCollectionReference<Either<Exception, location>>(collectionRef)
        .subscribeWithin(
      strictMode: true,
      center: GeoFirePoint(
        GeoPoint(
          userPosition.latitude,
          userPosition.longitude,
        ),
      ),
      radiusInKm: radiusInKm,
      field: geo,
      geopointFrom: (data) => data.fold(
          (l) => throw Exception('Unexpected error'),
          (location) => GeoPoint(
            location.geo.geopoint.latitude,
            location.geo.geopoint.longitude,
          ),
        ),
    )
        .map((snapshot) {
      return snapshot.isEmpty
          ? left(Exception())
          : right(
              snapshot
                  .map(
                    (doc) => doc.data()?.fold(
                          (l) => null,
                          (location) => location,
                        ),
                  )
                  .whereNotNull()
                  .toSet(),
            );
    });
  }

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