Flutter 保存在快照中并将其传输到double服务器的数据
您好,我想问一下如何从Firestore检索数据并将其发送给double 这是我从Firestore获取数据的代码Flutter 保存在快照中并将其传输到double服务器的数据,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,您好,我想问一下如何从Firestore检索数据并将其发送给double 这是我从Firestore获取数据的代码 Firestore.instance .collection('locations') .snapshots() .listen((driverLocation){ driverLocation.documents.forEach((dLocation){ dLoca
Firestore.instance
.collection('locations')
.snapshots()
.listen((driverLocation){
driverLocation.documents.forEach((dLocation){
dLocation.data['latitude'] = latitude;
dLocation.data['longitude'] = longitude;
print(latitude);
});
});
我将其存储在dLocation
中,当我打印(dLocation.data)时,它将在Firestore中显示纬度和经度。但是当我将它传递到双纬度
和双经度
时,它返回null
busStop.add(
Marker(
markerId: MarkerId('driverLocation')
,
draggable: false,
icon: BitmapDescriptor.defaultMarker,
onTap: () {
},
position: LatLng(latitude, longitude),
));
然后我想将双纬度
和双纬度
中的数据传递到标记中,以便标记将相应地移动到Firestore中的纬度和经度
Firestore.instance
.collection('locations')
.snapshots()
.listen((driverLocation){
driverLocation.documents.forEach((dLocation){
dLocation.data['latitude'] = latitude;
dLocation.data['longitude'] = longitude;
print(latitude);
});
});
这里发生的一切都处于
initState()
状态,您已反转了分配
Firestore.instance
.collection('locations')
.snapshots()
.listen((driverLocation){
driverLocation.documents.forEach((dLocation){
latitude = dLocation.data['latitude'] ;
longitude = dLocation.data['longitude'] ;
print(latitude);
});
});
试试这个:
Firestore.instance
.collection('locations')
.snapshots()
.listen((driverLocation) {
driverLocation.documents.forEach((dLocation){
var latitude = dLocation.data['latitude'];
var longitude = dLocation.data['longitude'];
print('latitude: $latitude, longitude: $longitude');
});
});
在纬度和经度中返回空值