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

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

Open
FabioCFonseca opened this issue Aug 20, 2024 · 0 comments
Open

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

FabioCFonseca opened this issue Aug 20, 2024 · 0 comments

Comments

@FabioCFonseca
Copy link

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