joscmw95 / geo_firestore

GeoFirestore for Flutter to do location based queries with Firestore
MIT License
10 stars 8 forks source link

getAtLocation returning an empty list #2

Open ggutenberg opened 4 years ago

ggutenberg commented 4 years ago

I've tried the following code, but it's failing to retrieve any snapshots. Using the node.js library works fine with the same center coordinates and same Firestore collection.

Working (node.js):

export const getNear = async (center: number[], radius: number) => {
  const geofirestore: GeoFirestore = new GeoFirestore(firestore);
  const geocollection: GeoCollectionReference = geofirestore.collection(
    "businesses"
  );
  const query: GeoQuery = geocollection.near({
    center: new admin.firestore.GeoPoint(center[0], center[1]),
    radius
  });
  const queryResults = await query.get();
  console.log(queryResults.docs);
  return queryResults.docs.map(doc => doc.data());
};

const getNearResponse = await business.getNear(
  [-1.7970149, -80.757148],
  1000
);

Not working (Dart):

  _populateBusinesses() async {
    final GeoFirestore geocollection =
        GeoFirestore(firestore.collection('businesses'));
    final queryLocation = GeoPoint(-1.7970149, -80.757148);
    List<DocumentSnapshot> snapshots =
        await geocollection.getAtLocation(queryLocation, 1000);
    // snapshots is always an empty List
    final documents = snapshots.map((doc) {
      return doc.data;
    }).toList();
    setState(() {
      _documents = documents;
    });
  }

I managed to trace the calls into this lib, and it seems the issue is occurring in queriesAtLocation(). Specifically in this series of calls:

    queries.add(queryForGeoHash(geoHash, queryBits)); // queries.single: GeoHashQuery
    queries.add(queryForGeoHash(geoHashE, queryBits)); // queries.single: GeoHashQuery
    queries.add(queryForGeoHash(geoHashW, queryBits)); // queries.single: GeoHashQuery
    queries.add(queryForGeoHash(geoHashN, queryBits)); // queries.single: Unhandled exception: Bad state: Too many elements
    // After this things seem broken
    queries.add(queryForGeoHash(geoHashNE, queryBits));
    queries.add(queryForGeoHash(geoHashNW, queryBits));
    queries.add(queryForGeoHash(geoHashS, queryBits));
    queries.add(queryForGeoHash(geoHashSE, queryBits));
    queries.add(queryForGeoHash(geoHashSW, queryBits));