【发布时间】:2020-08-31 00:43:31
【问题描述】:
// 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()))));
当我执行上述操作时,它无法正常工作。 但如果我这样做,它会起作用:
let query = geoCollection.where("status", "==", "active")
或
let query = geoCollection.near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 1000 });
但不能在一起!这就是我想要的。
这是文档的链接。它不是很详细,但我尽力查看文件,到目前为止没有运气。 https://firebaseopensource.com/projects/geofirestore/geofirestore-js/
【问题讨论】:
-
我在为您的问题研究解决方案时看到了一些示例,所以这绝对是可能的,但我注意到的一件事是每个示例都使用
.near().where()而不是您正在使用的where().near()这可能是为什么不起作用的情况,请尝试进行更改并让我知道它是否有效。 -
@ralemos,感谢您的帮助。无论如何,它也没有工作。我看了这篇文章的一个答案,这正是你所说的 near().where() stackoverflow.com/questions/53027146/geofirestore-where-query。但不是运气。还有一种叫做查询的方法,它可以同时结合 where 和 near ,但在库中这个方法看起来是私有的。 geofirestore.com/classes/_geoquery_.geoquery.html#firestore
-
我试过这个:geoCollection.near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: radius }).native.where("status", "==", "active") 但现在 ".native" 忽略了 near()
-
"native" 实际上对我有用!
标签: firebase firebase-realtime-database google-cloud-firestore react-native-firebase geofirestore