【问题标题】:type 'String' is not a subtype of type 'double'“String”类型不是“double”类型的子类型
【发布时间】:2020-10-30 07:09:42
【问题描述】:

我想构建一个在谷歌地图上绘制标记的应用程序。这仍然很容易,但我希望 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'

【问题讨论】:

    标签: firebase flutter variables dart coordinates


    【解决方案1】:

    改变这一行

    position: LatLng(boatLatitude, boatLongitude));
    

    到这里:

    position: LatLng(double.parse('$boatLatitude'), double.parse('$boatLongitude')));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      相关资源
      最近更新 更多