【问题标题】:Want to get specific document fields from multiple documents in flutter cloud firestore想要从flutter cloud firestore中的多个文档中获取特定的文档字段
【发布时间】:2021-04-24 07:02:14
【问题描述】:

this image have the Database

我想抓取所有文档的经纬度,并显示在颤振地图(传单)中。

FlutterMap(
      options: MapOptions(
        center: latLng.LatLng(51.5, -0.09),
        zoom: 13.0,
      ),
      layers: [
        TileLayerOptions(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c']),
        MarkerLayerOptions(
          markers: [
            Marker(
              width: 80.0,
              height: 80.0,
              point: latLng.LatLng(51.5, -0.09),
              builder: (ctx) => Container(
                child: Icon(
                  Icons.circle,
                  size: 30,
                  color: dc,
                ),
              ),
            ),
          ],
        ),
      ],
    );

我将第 15 行仅作为示例,我想访问所有用户的 lat long 。请帮忙,提前谢谢

【问题讨论】:

  • 您必须获取所有文档,然后解析该字段您收到的文档数组
  • 如果我没有所有人的文档 ID,但必须访问所有人怎么办
  • 您可以通过FirebaseFirestore.instance.collection('collectionName').get()获取集合中的所有文档
  • 是的,现在我知道了如何获取数据,但是如何将所有这些 lat long 放入传单地图中,请帮助

标签: firebase flutter dart google-cloud-firestore fluttermap


【解决方案1】:
  • 首先,您必须为您的shopkeepers 获取文件。
  • 然后,遍历这些文档,提取您的 lat 和 lng 值,并将它们添加到列表中。

Future<List<LatLng>> getCordsFromFirebase() async {
List<LatLng> coordinatesList=[];
var results = await FirebaseFirestore.instance.collection('shopkeepers').get();

for (DocumentSnapshot item in results.docs){
coordinatesList.add(LatLng(item.data()['latitidue'], item.data()['longitude]));
 }
print('Length of cords list is: ' + coordinatesList.length.toString());//
return coordinatesList;
}

【讨论】:

    猜你喜欢
    • 2018-09-04
    • 1970-01-01
    • 2020-09-20
    • 2021-07-04
    • 2023-02-13
    • 2020-08-01
    • 2021-10-22
    • 2021-01-24
    • 1970-01-01
    相关资源
    最近更新 更多