我正在关注这个插件(学习)背景定位器。我以前使用过其他后台位置插件,但它们不再维护。
我正在按照插件描述中描述的教程进行操作,到目前为止这是我的代码。我不确定回调到底是什么以及如何使用它。
到目前为止,这是我的代码,但我没有得到任何结果。
static void backgroundLocationCallBack(LocationDto location) async {
await BackgroundLocator.initialize();
await BackgroundLocator.isServiceRunning();
}
void getLocationLiveUpdates() async {
return await BackgroundLocator.registerLocationUpdate(
backgroundLocationCallBack,
autoStop: false,
// disposeCallback: backgroundLocationDisposeCallBack,
androidSettings: AndroidSettings(
accuracy: LocationAccuracy.NAVIGATION,
interval: 5,
distanceFilter: 0,
client: LocationClient.google,
androidNotificationSettings: AndroidNotificationSettings(
notificationChannelName: 'Location tracking',
notificationTitle: 'Start Location Tracking',
notificationMsg: 'Track location in background',
notificationBigMsg:
'Background location is on to keep the app up-tp-date with your location. This is required for main features to work properly when the app is not running.',
notificationIconColor: Colors.grey,
)));
}
回调用于在某些事件期间执行某些操作。
在这里,callback
属性backgroundLocationCallBack
作为它的值,并且根据包代码,它用于在LocationDto
可用时执行适当的操作。该LocationDto
对象将包含您要查找的位置信息,您可以根据自己的用例使用它。
同样,disposeCallback
用于在BackgroundLocator
对象上调用 dispose 时执行某些操作。您可以执行诸如关闭所有为获取位置而打开的端口之类的操作。
还有其他回调,例如initCallback
和initDataCallback
用于设置回调以初始化位置服务的各种参数并分别为参数提供初始数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句