0

我正在尝试做的事情:

我有一个名为“用户”的集合,其中每个用户(文档)都有自己的纬度和经度保存在该文件中。有了这个,我正在尝试做一个看起来像这样的查询。

_firestore
        .collection('Users')
        .where('lat', isGreaterThanOrEqualTo: docLat)
        .where('lat', isLessThanOrEqualTo: maxLat)
        .where('lon', isGreaterThanOrEqualTo: docLon)
        .where('lon', isLessThanOrEqualTo: maxLon)

错误:

PlatformException(PlatformException(错误,除 whereEqualTo() 之外的所有 where 过滤器必须位于同一字段上。但您在 'lat' 和 'lon' 上有过滤器,null))


问题:

  1. 我不能在我的文档中使用GeoPoint作为类型。为什么?因为如果我将基于此进行搜索,则如下所示:

_firestore .collection('Users') .where('geopoint', isGreaterThanOrEqualTo: myGeopoint) .where('geopoint', isLessThanOrEqualTo: limitGeopoint)

不会起作用,因为它只会计算我的 GeoPoint 的纬度,而经度将被忽略。

  1. 我不能使用Geohash。如果以与 GeoPoints 相同的方式比较它们,它将无法向我显示所有结果,因为 geohash 的工作方式。

  2. 我知道一些包,比如firestore_helpersgeoflutterfire。但问题在于我不能限制结果集。我蚀刻得到所有这些或没有。或者,如果有任何想法如何限制它们,请告诉我(不,我不想限制收集结果,在将数据发送到其中一个包之前,请检查我的最后一个问题


我试图做的事情:

我负责firebase 中使用的综合指数,我把它们做成了这样。 在此处输入图像描述

但是查询仍然无法正常工作,对于我的案例,我无法找到任何复合索引的示例,但尚未在颤振(或至少飞镖)中使用。

据我了解,我需要使用类似这样的 Compose Index。

 _firestore
        .collection('Users')
        .where('lat_lon', isGreaterThanOrEqualTo: userData.geopoint.latitude.toString() + "_0.0")
        .where('lat_lon', isLessThanOrEqualTo: maxLimit.latitude.toString() + "_0.0")
        .where('lat_lon', isGreaterThanOrEqualTo:  "0.0_" + userData.geopoint.longitude.toString())
        .where('lat_lon', isLessThanOrEqualTo: "0.0_" +maxLimit.longitude.toString())

但也不起作用。你有什么解决办法吗?我真的需要找到一种方法来解决这个问题。

4

0 回答 0