【问题标题】:Print Latitude and longitude in FlutterFlutter中打印经纬度
【发布时间】:2022-11-29 02:40:26
【问题描述】:

我是 flutter 的新手,我正在努力解决应用程序中的错误。我想在 2 秒后打印当前用户的经纬度,我该怎么做?

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}");
          });
          // });
        }
      },
    );
  }

我正在使用此方法并在 Consumer 中调用它,但它总是运行 1 到 100 秒。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    使用Future.delayed

    void startTimer() async{
        await Future.delayed(Duration(seconds: 2));  
    
        print("My current location ${homeMapCtrl!.userCurrentLatLng}");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 2021-09-29
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多