Search code examples
cordovageolocation

Does geolocation act differently in background for certain cordova versions?


My app checks for the user's location every 5 minutes, which in most cases the app will be paused/be in the background. This used to work fine for me, however something I have done since I last checked has made it stop working when device is paused.

One of the key changes I have made is to change from phonegap build to cordova CLI, which also changes the cordova version my project uses. My best guess is that this is causing the issue. Can anyone tell me if that is a thing or not? Or what else it would likely be?


Solution

  • in your case i thin you have to create one new javascript and past my below code. and give this new javascript link in your index.html and also link cordova.js and add geolocation plugin. ok and copy my code.

    and in your index.html

    var Lati = localStorage.getItem('masterLati');

    var Long = localStorage.getItem('masterLong');

    using this if you pause your app still in app background this code will work. and still you have any confusion then message me.

    var watchID = null;
    
        $(function () {
            var options = { timeout: 50000 };
            watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
        });
    
        function onSuccess(position) {
            alert(position.coords.latitude);
            alert(position.coords.longitude);
            localStorage.setItem('masterLati',position.coords.latitude);
            localStorage.setItem('masterLong',position.coords.longitude);
    
        }
    
        function onError(error) {
           alert('Google Location Service is currently disable. Please On Google Location Service and Restart App.');
        }