Firestore 查询时间戳和 geohash 在一个查询中

问题描述

我正在尝试使用时间戳和 geohash 查询我的 Firestore 数据库,但结果一直作为空数组返回。如果我只使用 geohash 或只使用时间戳,那么我得到了结果,但是当我将它们一起使用时没有结果。运行此查询时,我也没有在控制台中收到任何错误。我不确定为什么这个查询不起作用,任何帮助将不胜感激。另外值得注意的是,我正在使用 Firebase 文档中建议的方法来处理 geohash 查询。这是查询的代码:

const bounds = geofire.geohashQueryBounds(center,radiusInM);
const promises = [];
for (const b of bounds) {
    const query = firebase
        .firestore()
        .collection('scheduledWorkouts')
        .where('date','>=',start) // start is a Firebase timestamp variable
        .where('date','<=',end) // end is a Firebase timestamp variable
        .orderBy('date')
        .orderBy('geohash')
        .startAt(b[0])
        .endAt(b[1]);
    promises.push(query.get());
}

Promise.all(promises)
    .then((snapshots) => {
        const matchingDocs = [];

        for (const snap of snapshots) {
            for (const doc of snap.docs) {
                const lat = doc.get('location.lat');
                const lng = doc.get('location.lng');

                // filtering out false positives
                const distanceInKm = geofire.distanceBetween(
                    [lat,lng],center
                );
                const distanceInM = distanceInKm * 1000;
                if (distanceInM <= radiusInM) {
                    matchingDocs.push(doc.data());
                }
            }
        }

        return matchingDocs;
    })
    .then((matchingDocs) => {
        console.log(matchingDocs);
    })
    .catch((error) => {
        console.log(error);
    });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)