想从 flutter cloud firestore 中的多个文档中获取特定的文档字段
Want to get specific document fields from multiple documents in flutter cloud firestore
this image have the Database
想抓取所有文档的经纬度显示在flutter map(leaflet)中
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 行放在示例中,我想访问所有用户的经纬度。请帮忙,提前致谢
- 首先,您必须为您的
shopkeepers
. 获取文件
- 然后,遍历这些文档,提取纬度和经度值,并将它们添加到列表中。
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;
}
this image have the Database
想抓取所有文档的经纬度显示在flutter map(leaflet)中
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 行放在示例中,我想访问所有用户的经纬度。请帮忙,提前致谢
- 首先,您必须为您的
shopkeepers
. 获取文件
- 然后,遍历这些文档,提取纬度和经度值,并将它们添加到列表中。
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;
}