首页 > 解决方案 > Firestore 查询在 Geoquery 中工作两次

问题描述

我正在使用 Geoquery 从 Android 中的 Firestore 获取最近的文档。但不知何故,startAfter(lastVisible)子句使查询为不同的绑定任务工作了两次。因此,在第一次获取之后,所有查询都会工作两次。

我的第一个查询是:

        List<GeoQueryBounds> bounds = GeoFireUtils.getGeoHashQueryBounds(center, radiusInM);
        final List<Task<QuerySnapshot>> tasks = new ArrayList<>();
        for (GeoQueryBounds b : bounds) {
            Query firstQuery = db.collection("posts")
                    .whereEqualTo("country_code", sharedpreferences.getString("country_code", ""))
                    .orderBy("geohash")
                    .startAt(b.startHash)
                    .endAt(b.endHash)
                    .limit(10);

            tasks.add(firstQuery.get());
        }

我的下一个查询是:


        List<GeoQueryBounds> bounds = GeoFireUtils.getGeoHashQueryBounds(center, radiusInM);
        final List<Task<QuerySnapshot>> nextTasks = new ArrayList<>();
        for (GeoQueryBounds b : bounds) {
            Query nextQuery = db.collection("posts")
                    .whereEqualTo("country_code", sharedpreferences.getString("country_code", ""))
                    .orderBy("geohash")
                    .startAt(b.startHash)
                    .endAt(b.endHash)
                    .startAfter(lastVisible)
                    .limit(10);

            nextTasks.add(nextQuery.get());
        }

标签: javaandroidgoogle-cloud-firestore

解决方案


推荐阅读