如何在颤振中节制onLocationChanged

时间:2020-10-08 15:48:12

标签: flutter dart geolocation location

我想每10分钟更新一次用户的位置。 onLocationChanged可以正常运行,即使应用程序在后台。但是,位置更改时,它会不断抛出位置详细信息。我希望它在10分钟后运行方法_getCurrentLocationtoServer()

location.onLocationChanged.listen((LocationData cLoc) {
      currentLocation = cLoc;
      _getCurrentLocationtoServer();
    });

void _getCurrentLocationtoServer() async{
//code to send to server
}

我正在使用https://pub.dev/packages/location软件包。

1 个答案:

答案 0 :(得分:0)

请勿在onLocationChanged内调用_getCurrentLocationtoServer()。只需分配currentLocation值即可。 现在,新建一个

matrix(Frame$RMSE, ncol = length(lb), dimnames = list(1:reps, lb))

这会定期运行,并每10分钟将currentLocation值发送到服务器。在将currentLocation值发送到服务器之前,请确保该值不为空。