现在,我的应用程序可以将用户位置连续发送到Firestore数据库。但我无法找到一种方法来仅访问的最新位置发送到Firestore的位置数据,以便我可以检索它并将其绘制到 map 中。
我正在使用以下方法将数据发送到Firestore。
_addGeoPoint(LatLng myloc) {
GeoFirePoint myLocation =
geo.point(latitude: myloc.latitude, longitude: myloc.longitude);
firestore
.collection('locations')
.add({'busName': 'WP9885','routeNo':'155','position': myLocation.data});
}
最佳答案
Firestore没有“最后”或“最新”数据的概念。如果要给集合中的文档增加时间感,则应在文档中添加store a server timestamp field。
如果每个文档中都有一个时间戳字段,则可以使用类似于以下代码的代码查询最近添加的文档:
firestore
.collection("locations")
.orderBy("location", "desc")
.limit(1)
关于flutter - 从Firestore数据库获取最新数据到Flutter App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63630683/