firebase - 'String'类型不是 'double'类型的子类型

标签 firebase flutter variables dart coordinates

我想构建一个在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/

相关文章:

javascript - 无法在多个文件中拆分 Firebase 函数

ios - Flutter 地理定位器插件 Geolocator().getCurrentPosition 不返回准确的 lng 和 lat 坐标

android - 无法加载库 : dlopen failed: library "libboost.so" not found

javascript - 如何在更新 mongo 文档时使用变量?

javascript - React SSR Firebase 应用程序中的图像

javascript - React 中的 Firebase 查询 - 我可以登录到控制台,但不能在组件中使用

image - 我可以将图像作为文件而不是数据存储在 Firebase 上吗 :url?

javascript - 如何在 flutter 中将一个图标更改为两个不同的图标?

javascript - 在对象中使用变量作为引用水平

PYTHON:使用 python 变量更新多列