xelita / angular-cordova-geolocation

Bring Apache Cordova Geolocation API to AngularJS Apps...
14 stars 8 forks source link

geolocation is not updated when app goes in background mode #3

Open exp-gokul opened 8 years ago

exp-gokul commented 8 years ago

Tried getCurrentPosition and watchPosition

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() {
        setTimeout(function() {
            cordovaGeolocationService.getCurrentPosition(function(position) {
                console.log("position inside take geolocations : ", position);
                var currentPosition = position;
                var latitude = currentPosition.coords.latitude;
                var longitude = currentPosition.coords.longitude;
                var string = 'lat:' + latitude + ':long' + longitude;
                // Modify the currently displayed notification
                cordova.plugins.backgroundMode.configure({
                    text: string
                });
            }, function errHandler(err) {
                console.log("error :", err);
            });
        }, 5000);
    }
}, false);