【问题标题】:Get the latest data from Firestore database into Flutter App从 Firestore 数据库中获取最新数据到 Flutter App
【发布时间】:2020-12-17 04:54:51
【问题描述】:

现在我的应用可以将用户位置连续发送到 Firestore 数据库。但我找不到仅访问发送到 Firestore 的最后位置数据的方法,以便我可以检索它并将其绘制到地图中。

我正在使用以下方法将数据发送到 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});
  }

【问题讨论】:

  • 您可以使用 StreamBuilder 将实时数据从 firebase 流式传输到您的应用中
  • “最后一个位置”是什么意思
  • @Taio 我指的是最新位置
  • @ShaileshBhokare 我调查一下

标签: flutter dart google-cloud-firestore


【解决方案1】:

Firestore 没有“最后”或“最新”数据的概念。如果您想为收藏中的文档添加时间感,您应该在文档中添加store a server timestamp field

如果您在每个文档中都有一个时间戳字段,那么您可以使用类似这样的代码查询最近添加的文档:

firestore
  .collection("locations")
  .orderBy("location", "desc")
  .limit(1)

【讨论】:

  • 所以你说的是每当数据被添加到 Firestore 时,我应该用它保存一个时间戳。然后编写一个查询,根据该时间对其进行排序并检索它。
  • 是的,这就是你需要做的。
  • 它对跟踪应用程序是否有效?
  • 不清楚你在问什么。如果您有新问题,请单独发布。
猜你喜欢
  • 1970-01-01
  • 2018-12-20
  • 1970-01-01
  • 1970-01-01
  • 2019-07-11
  • 1970-01-01
  • 2018-12-22
  • 2020-04-01
  • 1970-01-01
相关资源
最近更新 更多