Home > database >  Print Latitude and longitude in Flutter
Print Latitude and longitude in Flutter

Time:11-29

I am new in flutter, I am working on solving bugs in app. I want to print latitude and longitude of current user after 2 seconds, how can i do that?

void startTimer() {
    const oneSec = const Duration(seconds: 2);
    timer2 = new Timer.periodic(
      oneSec,
      (Timer timer) {
        if (start == 0) {
          timer.cancel();
          setState(() {});
          // });
        } else {
          // setState(() {
          start--;
          setState(() {
            print("My current location ${homeMapCtrl!.userCurrentLatLng}");
          });
          // });
        }
      },
    );
  }

I am using this method and i am calling it in Consumer but it always run upto 1 to 100 seconds.

CodePudding user response:

Use Future.delayed

void startTimer() async{
    await Future.delayed(Duration(seconds: 2));  

    print("My current location ${homeMapCtrl!.userCurrentLatLng}");

CodePudding user response:

Use location package to get user location or you can checkout this link for example click here

  • Related