0
Usecase:跟蹤關聯位置,只要他登錄,但稍後關閉應用程序。Cordova Background地理位置服務器更新
使用https://github.com/mauron85/cordova-plugin-background-geolocation插件。 在調試模式下,它顯示值,但是在回調函數中,它不會調用服務器。 renderMaps函數調用navigator.geolocation.getCurrentPosition
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use device APIs
renderMaps();
var callbackFn = function(location) {
var data = 'longitude='+ location.longitude + '&latitude=' + location.latitude + '&id=' + vm.user_id + '&token=' + vm.accessToken;
window.longitude_sel = location.latitude;
window.latitude_sel = location.longitude;
console.log("" + data);
$.ajax({
type: "POST",
url: "https://example.com/partner/location",
data: data,
success: function(response){
console.log("RESPONSE" + response);
}
});
backgroundGeolocation.finish();
};
var failureFn = function(error) {
console.log('BackgroundGeolocation error');
};
// BackgroundGeolocation is highly configurable. See platform specific configuration options
backgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 5,
stationaryRadius: 0,
distanceFilter: 30,
interval: 60000,
stopOnTerminate: false,
startOnBoot: false,
startForeground: true,
stopOnStillActivity: false,
debug: true
});
backgroundGeolocation.start();
console.log("TEST");
}