GeoFirestore-是否可以在GeoQuery中组合near()和where()方法? [英] GeoFirestore - Is it possible to combine the methods near() and where() in a GeoQuery?
本文介绍了GeoFirestore-是否可以在GeoQuery中组合near()和where()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//查询让查询= geoCollection.where(状态","==",活动").near({中心:new firebase.firestore.GeoPoint(纬度,经度,半径:1000}));//订阅,将作业添加到存储中并侦听更改query.onSnapshot((res)=> res.docs& Array.from(res.docs.map((doc)=> console.log(doc.data())))));
当我执行上述操作时,它无法正常工作.但是如果我这样做,它会起作用:
让query = geoCollection.where("status","==","active")
或
让查询= geoCollection.near({中心:new firebase.firestore.GeoPoint(纬度,经度,半径:1000}));
但不能在一起!这就是我想要的.
这是文档的链接.它不是很详细,但是我尽力调查了文件,到目前为止还没有运气.
解决方案
终于找到了解决方案.要求您在Cloud Firestore控制台中创建索引.
- 在我的情况下,您在第一个字段中输入的收藏名称是工作"
- 将"where"放置在字段(升序)中要与之进行比较的媒体资源
- 最后,键入
g.geohash
(升序) - 单击保存",然后等待大约5到10分钟.
// Queries
let query = geoCollection
.where("status", "==", "active")
.near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 1000 });
// Subscribe, add jobs into store and listen for changes
query.onSnapshot((res) => res.docs && Array.from(res.docs.map((doc) => console.log(doc.data()))));
When I perform the above it doesn't work properly. but if I do this instead it works:
let query = geoCollection.where("status", "==", "active")
or
let query = geoCollection.near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 1000 });
But not together! Which is what I want.
Here is the link for the Documentation. It's not very detailed, but I tried my best to look into the files and no luck so far. https://firebaseopensource.com/projects/geofirestore/geofirestore-js/
Here is a picture of the structure:
解决方案
Finally found a solution. It is required that you create an Index in the Cloud Firestore console.
- Put your collection name in the first field in my case was "jobs"
- Put the "where" property that you are comparing to in the field (Ascending)
- Lastly, type
g.geohash
(Ascending) - Click Save, and wait around 5 and 10 minutes.
这篇关于GeoFirestore-是否可以在GeoQuery中组合near()和where()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文