GPS coordinates in background in cordova app
<p>I'm currently doing a hybrid app using ionic/cordova. 
The app needs functionality where it pings our backend with its location every 1 minute or so and the backend API will answer if anything interesting is nearby.
If the answer is yes the app will queue a local notification which hopefully will make the user open the app.
This functionality is needed when the app is in background mode and even when the phone is locked.
The app needs to be able to be deployed to both app store, google play and eventually windows phone.</p>

<p>I'm currently using a combination of these three plugins:</p>

<p><a href="https://www.npmjs.com/package/cordova-plugin-geolocation" rel="noreferrer">https://www.npmjs.com/package/cordova-plugin-geolocation</a>  - for location
<a href="https://github.com/katzer/cordova-plugin-background-mode" rel="noreferrer">https://github.com/katzer/cordova-plugin-background-mode</a> - for bg mode
<a href="https://github.com/katzer/cordova-plugin-local-notifications" rel="noreferrer">https://github.com/katzer/cordova-plugin-local-notifications</a> - for local notifications</p>

<p>This currently works on Android when the device is not locked (so it works in foreground and background mode) but when the device is locked it is unable to get the GPS coordinates.</p>

<p>My code currently looks like this:</p>

<pre><code>        // Enable background worker          
        (cordova as any).plugins.backgroundMode.enable();

   intervalPromise = $interval(intervalWork, 30000, 0, false);

    function intervalWork() {
        $log.log('Trying to fetch pos');

        var options = { maximumAge: 30000, timeout: 30000, enableHighAccuracy: false };

        navigator.geolocation.getCurrentPosition(success,
            err,
            options);
    }

    function success(pos) {
        $log.log("lat: " + pos.coords.latitude + " long: " + pos.coords.longitude);

        var Checkin = $resource(ApiDataEndpoint.url + 'checkin/:lat/:lng/', {});

        var res= Checkin.get({ lat: pos.coords.latitude, lng: pos.coords.longitude });

               if (res) { 

                $cordovaLocalNotification.schedule({
                    id: 1,
                    title: 'test',
                    text: 'test',
                }).then(function(result) {
                    $log.log("ok");
                });
            };
         }
</code></pre>

<p>So... my questions are:</p>

<p>1) How to get the solution to work when my device is locked (the getCurrentPosition is called even when device is locked but returns timeout)?</p>

<p>2) Is it possible to get this solution to work on iOS?</p>

<p>3) Will an app made this way be approved in google play and app store?</p>

<p>4) If the project is doomed what are my alternatives?</p>

<p>I really need help on this one!</p>