Firestore 的 GeoFlutterFire Flutter 插件不返回距离字段

Sam*_*ord 5 geofire flutter google-cloud-firestore

我正在使用GeoFlutterFire,这是 Flutter 的一个插件,它筛选指定 GeoFirePoint 附近记录的集合。
距离键应该与 Firestore 一起返回,<DocumentSnapshot>s但没有返回,只有默认键。当我如下寻找它时,它返回空值。钥匙不存在。

  1. 我试过更改模拟器 GPS 位置,然后更改 usersAddressGeoFirePoint,但不走运。
  2. 关于 GeoFire 是创建此字段还是需要它作为 Firestore 字段预先存在,说明不清楚。我尝试使用虚拟值手动创建 Firestore 字段,然后我从下载中获得的值不是两点之间的距离,geopoint而是它在 Firestore 上设置的虚拟值。

这是非常令人沮丧的,我需要距离以便我可以在应用程序的卡片上显示它,我的代码非常接近插件的示例代码,所以我不明白为什么它不起作用。

GeoFirePoint usersAddressGeoFirePoint = 
        geo.point(latitude: 56.088944, longitude: -4.151800);
    
localJobsStream = geo.collection(collectionRef: myFirestore.collection('JobsMeta'))
            .within(center: usersAddressGeoFirePoint, radius: 1000, field: 'position', strictMode: true);
    
localJobsStream.listen((List<DocumentSnapshot> documentList) {
    ${documentList[0].data.keys.contains('distance')}");
    }
Run Code Online (Sandbox Code Playgroud)

Arp*_*pit 5

我检查了 Geoflutterfire 的内(中心:中心,半径:半径,字段:字段,strictMode:strictMode)方法,它Stream<List<DocumentSnapshot>>按预期返回 ,但对于距离计算,它使用了一个包装类DistanceDocSnapshot,它有一个 DocumentSnapshot 和距离变量。

当我调试“within”方法时,我发现 DistanceDocSnapshot 有一个double 类型的可变距离,但它们在返回之前没有在DocumentSnapshot 中设置距离值。

所以这个包有数据但在我们得到它之前没有用。当他们解决此问题或我们了解使用它的任何其他方式时,您可以使用以下代码来获取距离,因为他们在包中使用相同的代码并在自述文件中提到GeoFlutterFire Package

 GeoFirePoint center = geo.point(
     latitude: currentUserPos.latitude,
     longitude: currentUserPos.longitude,
 );

 double distance = center.distance(lat: geoPoint.latitude, lng: geoPoint.longitude);
Run Code Online (Sandbox Code Playgroud)

更新相同:根据包页面上的更改日志,我们将无法再使用 doc.data['distance']版本 2.1.0访问数据