Firestore 最近添加了在单个查询中的多个字段上具有不等式和范围条件的功能。
我认为可以分别查询 GeoPoints 的纬度和经度。例如,我有以下地理点: 在此输入图片描述
如果我创建以下查询,即使 fromGeopoint.latitude 大于 0.0 并且 fromGeopoint.longitude 大于 -1.0,我也无法检索文档。
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('collection-name')
.where('fromGeopoint.latitude', isGreaterThan: 0.0)
.where('fromGeopoint.longitude', isGreaterThan: -1.0)
.snapshots()
我的做法有问题吗?我知道我可以使用 geohashes 或 GeoFlutterFire 执行类似的查询,但我很想知道这是否可能是潜在的地理查询解决方案。谢谢。
我不确定是否可以直接访问纬度/经度。人们声称这是可能的。但是,它在我的情况下不起作用。我在“where”子句中尝试了不同的字符串,例如 fromGeopoint.Latitude (大写 L,因为这是它在 Firestore 中的存储方式)或 fromGeopoint.latitude() (这没有任何意义,但我在玩)等
如果我创建以下查询,即使 fromGeopoint.latitude 大于 0.0 并且 fromGeopoint.longitude 大于 -1.0,我也无法检索文档。
这是预期的行为,因为当您以这种方式调用
where
时:
.where('fromGeopoint.latitude', isGreaterThan: 0.0)
这意味着
fromGeopoint
字段是一个包含名为 latitude
的键的 Map(对象),这是不正确的,因为 fromGeopoint
字段是 GeoPoint 类型的字段。
我认为可以分别查询 GeoPoints 的纬度和经度。
除非您将纬度和经度保存在两个不同的单独字段中,否则您无法做到这一点。
如果要使用预定义的 GeoPoint 查询集合,则必须将 GeoPoint 对象传递给
where
函数,而不是浮点数。