【问题标题】:I cant get data from my firestore db using geofirestore in express我无法在 express 中使用 geofirestore 从我的 firestore 数据库中获取数据
【发布时间】:2019-10-30 09:11:42
【问题描述】:

我在 express 中创建了一个查询来提取我的数据 这是我的端点快速函数:

app.get('/locatii', (req, res) => {
    const geofirestore = new GeoFirestore(db);
    const geocollection = geofirestore.collection('locatii2');
    const query = geocollection.near({
        center: new firebase.firestore.GeoPoint(45.831922, 27.431149),
        radius: 3000
    });
    query.get().then(snap => {
        console.log(snap.docs())
        let places = [];
        snap.forEach(doc => {
            places.push(doc.data());
            console.log(doc.data())
        });
        res.json(places);
    })
        .catch(err => res.send(err));
});

下面是我的火痛结构: 当我访问我的端点时,它不会显示在控制台数据或邮递员中。我不知道我错过了什么。谢谢!

【问题讨论】:

    标签: javascript express google-cloud-firestore geofirestore


    【解决方案1】:

    您的数据结构中似乎没有 geohash。为了能够按位置查询这些文档,需要在每个文档中都有一个 geohash。

    从 GeoFirestoreJS 附带的 example app 看来,您似乎可以使用类似以下内容的 get the geohash

    location.lat = ...
    location.lng = ...
    const hash = geokit.Geokit.hash(location);
    

    然后将其设置到您的 Firestore 文档中,如下所示:

    documentRef.update(hash);
    

    【讨论】:

    猜你喜欢
    • 2021-08-15
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多