【问题标题】:Background Location - Flutter背景位置 - Flutter
【发布时间】:2020-12-28 08:29:10
【问题描述】:

我在颤振中开发了一个应用程序来捕获坐标。下面的代码正在正确捕获坐标,但问题是,当应用程序关闭时它不起作用。即使应用程序关闭,我也需要捕获位置。任何帮助将不胜感激

@override
void initState() 
{
 super.initState( );
 BackgroundLocation.startLocationService( );
 BackgroundLocation.getLocationUpdates( (location) async {
  setState( () {
    debugPrint(globals.sUserCode);
    debugPrint(globals.sActiveTripCode);
    this.latitude = location.latitude.toString( );
    this.longitude = location.longitude.toString( );
    this.accuracy = location.accuracy.toString( );
    this.altitude = location.altitude.toString( );
    this.bearing = location.bearing.toString( );
    this.speed = location.speed.toString( );
    this.time =
        DateTime.fromMillisecondsSinceEpoch( location.time.toInt( ) )
            .toString( );
  } );
 }

【问题讨论】:

    标签: flutter dart geolocation latitude-longitude


    【解决方案1】:

    我在项目中使用了这样的package。但是这个包有一定的限制。为额外使用付费。我们尝试了您所做的所有方法。但它没有发生。要么你必须通过 ios 和 android 从头开始​​编写。否则,您可能别无选择。由于时间有限,我们别无选择,只能购买此套餐。而且效果很好。

    【讨论】:

      【解决方案2】:

      当您的应用关闭时,UI Isolate 不会运行。您需要将您的地理资料移动到第二个 Isolate,以便它可以继续运行。看看 Google 对此有何评论:https://flutter.dev/docs/development/packages-and-plugins/background-processes

      【讨论】:

        【解决方案3】:

        您也可以考虑this plugin,它有一个非常慷慨的免费套餐,并包含额外的地理 API 和跟踪功能。

        【讨论】:

          猜你喜欢
          • 2014-12-29
          • 2013-01-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-06
          • 1970-01-01
          • 2019-06-20
          相关资源
          最近更新 更多