javascript - 我无法在 express 中使用 geofirestore 从我的 firestore db 获取数据
问题描述
我在 express 中创建了一个查询来提取我的数据,这是我的端点 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));
});
解决方案
您的数据结构中似乎没有 geohash。为了能够按位置查询这些文档,需要在每个文档中都有一个 geohash。
从 GeoFirestoreJS 附带的示例应用程序中,您似乎可以通过以下方式获取 geohash:
location.lat = ...
location.lng = ...
const hash = geokit.Geokit.hash(location);
然后将其设置到您的 Firestore 文档中,如下所示:
documentRef.update(hash);
推荐阅读
- java - Firebase NullPointerException 错误,虽然有用户 ID
- github - 为什么我尝试在 Git Hubs 平台上发布网站时在 Github 上得到 404
- java - Java 对象 - 如何动态创建对象
- c# - Zipwise.com 无法创建 SSL/TLS 安全通道
- python - 使用 OpenCV 检测并替换从一张图像到另一张图像的区域
- c# - C# OpenGL OpenTK - 当我调整 eye.X 值时,相机会远离绘图
- javascript - 有没有办法阻止chrome使用javascript在chrome的下拉列表中显示建议?
- c++ - 使用make将一个目录下的所有cpp文件编译成自己的g++可执行文件
- python - 如何将随机项目从列表转换为字符串?
- c# - 如何在String C#中将单词或单词获取为char