我想构建一个在Google map 上绘制标记的应用程序。这仍然很容易,但是我希望Firebase提供标记的纬度和经度值。我使用下面的代码进行了尝试,并且一切正常(我可以打印两个值),但标记已绘制。
这是我尝试的代码:
var boatLatitude;
var boatLongitude;
void getBoatLocation() {
FirebaseDatabase.instance
.reference()
.child('latitudeBoot')
.onValue
.listen((event) {
print('-----------------------' + event.snapshot.value);
setState(() {
boatLatitude = event.snapshot.value;
});
});
FirebaseDatabase.instance
.reference()
.child('longitudeBoot')
.onValue
.listen((event) {
print(event.snapshot.value + '----------------------');
setState(() {
boatLongitude = event.snapshot.value;
});
Marker c = Marker(
markerId: MarkerId('3'),
icon: customIconBoat,
position: LatLng(boatLatitude, boatLongitude));
setState(() {
markers.add(c);
});
});
}
我在应用启动时调用上面的函数。问题是我收到此消息,但不知道如何解决该问题:
E/flutter (22304): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'String' is not a subtype of type 'double'
最佳答案
改变这条线
position: LatLng(boatLatitude, boatLongitude));
对此:position: LatLng(double.parse('$boatLatitude'), double.parse('$boatLongitude')));
关于firebase - 'String'类型不是 'double'类型的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62819093/