类型 'String' 不是类型 'double' 的子类型
type 'String' is not a subtype of type 'double'
我想构建一个在 google 地图上绘制标记的应用程序。这仍然很容易,但我希望 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')));
我想构建一个在 google 地图上绘制标记的应用程序。这仍然很容易,但我希望 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')));