0
我正在用背景地理位置插件https://github.com/mauron85/cordova-plugin-background-geolocation
构建一个离子应用程序。重启后的科尔多瓦背景地理位置插件
我想让应用程序在重启后发送它的位置。我正在使用的插件似乎有选择,但它不能正常工作。只有在每次启动后至少执行一次应用后,应用才会将其位置发送到服务器。
任何帮助或建议,将不胜感激。先谢谢你!
我的代码如下
配置
backgroundGeolocation.configure(callbackFn, failureFn, {
locationProvider: backgroundGeolocation.provider.ANDROID_ACTIVITY_PROVIDER,
desiredAccuracy: 10,
stationaryRadius: 10,
distanceFilter: 10,
interval: 60000,
maxLocations: 50,
startOnBoot: true, // from my understanding, this should make an app track its location even after reboot
stopOnTerminate: false
});
回调函数
var callbackFn = function(location) {
console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
// Do your HTTP request here to POST location to your server.
var link = API_URL;
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http({
method: 'POST',
url: link,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
params: {
'device': 'android',
},
data: {
lat:location.latitude,
lng:location.longitude,
}
}).success(function(data){
console.log(data);
}).error(function(data){
console.log(data);
});
backgroundGeolocation.finish();
};
我可以在配置中使用选项'url'重新启动后获取设备的位置。回调函数在重新启动后被终止,但是,当您使用配置选项发布设备的位置时,设备仍会将其位置发送到服务器。尝试在配置中使用选项'url'。检查文档 – smchae
如何使用像watchPosition函数这样的回调函数我的意思是我希望在应用程序在后台运行时定期按特定时间间隔获取设备的位置,我需要绘制折线。 –