GeoFire与实时数据库紧密耦合,而地理查询是许多希望迁移到Firestore的应用程序的常见功能依赖.有没有办法在Firestore环境中复制散列/检索位置?
firebase geofire firebase-realtime-database google-cloud-firestore
新的Firestore DB允许我存储GeoPoints.有没有办法根据它们进行查询?
因此,例如,如果我的每个集合文档都有一个location类型的字段geopoint.如何将最近的10个文档放到任意坐标?
文档似乎没有涵盖这一点.我试过这样的东西:
someRef.where('location', '>', geopoint).limit(10).get();
Run Code Online (Sandbox Code Playgroud)
显然这没有多大意义,但我只是在尝试一些东西
我正在查询 firestore 集合以查找纬度和经度范围内的文档。由于看来您无法使用给定两个不同字段(“lat”、“lon”)的参数进行查询,因此我已将 Geopoint 类型分配给具有经度和纬度的单个字段“coords”。如何将 .where() 与地理点一起使用?下面是我想要使用的一般查询,其中 _latMin、_latMax 等是链接到地图边界框的变量。
_getDocs() async {
print('getdocs');
final QuerySnapshot snapshot = await FirebaseFirestore.instance
.collection('collectionName')
.where(
'coords',
isGreaterThan: _latMin,
isLessThan: _latMax,
)
.where(
'coords',
isGreaterThan: _lonMin,
isLessThan: _lonMax,
)
.get();
snapshot.docs.forEach((DocumentSnapshot doc) {
print(doc.data());
});
}
Run Code Online (Sandbox Code Playgroud)
如何引用坐标内的纬度和经度?