SOS video
SOS video

Reputation: 476

type 'String' is not a subtype of type 'double'

I want to build an app that draws a marker on a google map. That's still easy, but I want firebase to give the marker latitude and longitude values. I tried it with the code below and everything worked (I can print the two values) except that the marker is drawen.

This is the code I tried:

  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);
      });
    });
  }

I call the function above when the app starts.

The problem is that I get this message and I don't know how I can solve the problem:

E/flutter (22304): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'String' is not a subtype of type 'double'

Upvotes: 0

Views: 595

Answers (1)

Payam Asefi
Payam Asefi

Reputation: 2757

change this line

position: LatLng(boatLatitude, boatLongitude));

to this:

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

Upvotes: 4

Related Questions