Firestore中GeoPoint经纬度单独查询文档失败,咨询问题排查与方案
Firestore GeoPoint跨字段范围查询问题解答
直接通过fromGeopoint.latitude和fromGeopoint.longitude构建跨字段范围查询的方案不可行,原因如下:
- Firestore的GeoPoint是原子型特殊字段类型,并非可拆分的嵌套对象。你用
fromGeopoint.latitude这种点语法访问属性时,Firestore无法识别对应字段——不管尝试首字母大写、加括号调用方法都没用,因为这种路径查询仅对嵌套键值对字段有效,GeoPoint不属于这类结构。 - 虽然Firestore新增了单查询多字段不等式/范围条件支持,但该规则仅适用于独立顶级字段或嵌套对象的子字段,不适用于GeoPoint类型的内部属性。
你提到的geohash前缀查询、GeoFlutterFire库是Firestore实现地理范围查询的可行方案,也是官方推荐的常规做法。
附你测试用的代码:
StreamBuilder<QuerySnapshot>( stream: FirebaseFirestore.instance .collection('collection-name') .where('fromGeopoint.latitude', isGreaterThan: 0.0) .where('fromGeopoint.longitude', isGreaterThan: -1.0) .snapshots() )
内容的提问来源于stack exchange,提问作者nikosrope
相关产品推荐
相关产品推荐

