【问题标题】:GeoFirestore - Is it possible to combine the methods near() and where() in a GeoQuery?GeoFirestore - 是否可以在 GeoQuery 中结合 near() 和 where() 方法?
【发布时间】: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


【解决方案1】:

终于找到了解决办法。您需要在 Cloud Firestore 控制台中创建索引。

  1. 在我的例子中,将您的集合名称放在第一个字段中是“工作”
  2. 将要比较的“where”属性放入字段中(升序)
  3. 最后,输入g.geohash(升序)
  4. 点击保存,然后等待大约 5 到 10 分钟。

【讨论】:

  • 这是如何工作的?你不能有 Where in Nearby 查询!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
  • 2013-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多