Akb*_*arB 6 geolocation firebase flutter google-cloud-firestore
在我的“办公室”集合中,我正在使用 GeoFlutterFire 包尝试查询 x 年和 y 年之间建造的所有办公室,提供特定服务且距离我办公室 z 英里以内。每个“办公室”文档都有一个“位置”地图,其中包含使用 GeoFirePoint 的 geohash 和地理点,以及“建造年份”和“服务”字段。我喜欢执行如下查询并获取文档并显示它们:
var collRef = firestore.collection('offices')
.where('service', isEqualTo: 'law')
.where('built', isLessThanOrEqualTo: y)
.where('built', isGreaterThanOrEqualTo: x);
geo.collection(collectionRef: collRef.reference())
.within(center: myOffice, radius: z, field: 'position', strictMode: true);
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。我收到此查询无效的错误:
Unhandled Exception: PlatformException(invalid_query, FIRInvalidArgumentException, Invalid query. You have a where filter with an inequality (lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) on field 'built' and so you must also use 'built' as your first queryOrderedBy field, but your first queryOrderedBy is currently on field 'position.geohash' instead.)
Run Code Online (Sandbox Code Playgroud)
我知道我们不能对 Firebase 中的多个字段做不等式,因为这就是索引的工作原理,我猜 GeoFlutterFire 会根据 geohash 进行内部排序,但我试图避免客户端查询,以尽可能避免不必要的文档读取,所以这就是为什么我需要在这里合并所有查询!
如果我在这里进行位置查询,然后在客户端进行构建年份,我最终会阅读很多不必要的文档。反之亦然(根据构建年份进行查询并在客户端处理位置)。有没有解决的办法?
| 归档时间: |
|
| 查看次数: |
772 次 |
| 最近记录: |