0
即使應用程序在後臺處於休眠狀態並將其存儲在數據庫中,我也打算獲取用戶地理位置。 我使用katzer的科爾多瓦背景插件, 當我嘗試訪問backgroundMode.onactivate
函數中的navigator.geolocation.getCurrentPosition
函數時,什麼也沒有發生,而當我嘗試傳遞硬編碼值時調用api,數據存儲在數據庫中。離子應用程序中的地理位置報告背景
下面是我的代碼
document.addEventListener('deviceready', function() {
// Android customization
cordova.plugins.backgroundMode.setDefaults({
text: 'Doing heavy tasks.'
});
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function() {
console.log('inside background')
a();
}
var a = function() {
console.log('a called')
navigator.geolocation.getCurrentPosition(function(pos) {
console.log('inside navigate');
var data = {
Lati: '123456',
Longi: '132456',
//LoginID: JSON.parse(window.localStorage.getItem('LoginId'))
EmpCode: localStorage.getItem('LoginId')
};
$http.post("https://app.sbismart.com/bo/ContactManagerApi/UpdateEmployeeLoc", data).success(function(rsdata, status) {
console.log('inside rsdata');
console.log(data.Lati + "," + data.Longi);
})
}, function(error) {
alert('Unable to get location: ' + error.message);
});
}
}, false);