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函數這樣的回調函數我的意思是我希望在應用程序在後臺運行時定期按特定時間間隔獲取設備的位置,我需要繪製折線。 –