2015-10-21 51 views
0

我的应用程序每5分钟检查用户的位置,在大多数情况下,应用程序将被暂停/位于后台。这对我来说工作得很好,但是自从我上次检查以来,我所做的一些工作使设备暂停时停止工作。某些科尔多瓦版本的地理位置在背景中的行为是否有所不同?

我所做的一个主要更改是从phonegap构建更改为cordova CLI,这也改变了我的项目使用的cordova版本。我最好的猜测是这是造成这个问题。任何人都可以告诉我这是不是一件事?或者它可能是什么?

回答

2

在你的情况下,我瘦你必须创建一个新的JavaScript和过去我的下面的代码。并给您的这个新的JavaScript链接在您的index.html和链接cordova.js添加地理位置插件。好吧,并复制我的代码。

在您的index.html

变种拉提= localStorage.getItem( 'masterLati');

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

使用这个,如果你暂停你的应用程序仍然在应用程序背景此代码将工作。你仍然有任何困惑,然后给我发消息

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.'); 
    }