Angular js cordovaGeolocation getting current position and Sending Data to Server in Background


Hey Guys, i was trying cordovaGeolocation ngCordova Geolocation i have inserted the same code in my app it works fine for me when the app is open, I need to get this geolocation and send it to server while the app is in background, So used background mode cordova see backgroundMode documentation Cordova Background Mode.

  1. I am getting the geolocation and sending to server is working fine when the app is open.

  2. I have used onpause and onresume cordova also for the app state like in native android.

  3. When the app is in onpause, i have used background enable(), inside onactivate(), given interval and getting geolocation and sending to service.

  4. Once the app goes to onpause and returning to onresume app gets the geolocation and sending to server perfectly.['$rootScope', '$location','$mdToast','$cordovaPush', '$sessionStorage', '$cordovaDevice', '$cordovaLocalNotification', '$timeout','$cordovaGeolocation','$interval','Service', function($rootScope, $location,$mdToast,$cordovaPush, $sessionStorage, $cordovaDevice, $cordovaLocalNotification, $timeout,$cordovaGeolocation,$interval,Service) { document.addEventListener("resume", function() { console.log("The application is resuming from the background"); cordova.plugins.backgroundMode.disable(); }, false); document.addEventListener("pause", function() { console.log("The application is pausing to the background"); cordova.plugins.backgroundMode.enable(); }, false); var i=0; cordova.plugins.backgroundMode.onactivate = function () { console.log("notificationReceived"); setInterval(function () { console.log("interval: "+ i++); var posOptions = {timeout:3000,enableHighAccuracy: false}; $cordovaGeolocation .getCurrentPosition(posOptions) .then(function (position) { var GeoLocation=new Object(); GeoLocation.geo_location_latitude=position.coords.latitude; GeoLocation.geo_location_longitude=position.coords.longitude; Service.CurrentService(GeoLocation).success(function(data){ console.log(new Date()); console.log("cur loc: "+JSON.stringify(data)); }).error(function(data){ console.log("error: "+JSON.stringify(data)); }) }, function(err) { console.log("Error: "+err); // here Position Error Occurs // error }); },60000); } })];

The Error is When the app closes or goes the onpause, getting Position Error message: Timeout expired while getting geolocation and not sending data to server. Please see to this coding and guide me to complete this. Thank You in advance.