【问题标题】:phonegap Auto Send Gps Position to Mysql Server. Even application is not openedphonegap 自动发送 Gps 位置到 Mysql 服务器。连申请都打不开
【发布时间】:2015-04-20 05:07:13
【问题描述】:

我使用 phonegap/cordova 在 android 上创建应用程序。快递员将使用它来交付产品。他们的 Android 应用程序会在每个周期/特定时间自动向服务器发送 gps 坐标。

但我的问题是:只有打开应用程序才能做得很好。我该怎么做才能让它运行,即使我的 android 应用程序没有打开。

这是我的代码

function onDeviceReady() 
    {
    var deviceID = device.uuid;
   localStorage.setItem('pinid',deviceID);
    var options = { frequency: 3000 }; //THIS I SPECIFY INTERVAL TIME TO SEND POSITIONS
    watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
    }

function onSuccess(position) 
{

var lat = position.coords.latitude;
var lng = position.coords.longitude;
var get_pinid="";
var get_pinid=localStorage.getItem('pinid');

$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?latlng='+position.coords.latitude+','+position.coords.longitude+'&sensor=false', function(data) {
alamats = data.results[0];
localStorage.setItem('alrum',alamats.formatted_address);

});
var al="";
var al=localStorage.getItem('alrum');
    //SEND TO SERVER
$.ajax({
      type: "POST",
      url: "http://www.domain.com/demo_android/set_position.php?",
     data: "addr=" +al+ "&langi="+ lat + "&longi="+ lng+ "&devi="+ get_pinid,
      cache: false,
      success: function(html){
      }
    });


}

function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

【问题讨论】:

    标签: android mysql cordova


    【解决方案1】:

    您需要使用 Cordova 后台服务插件将您的应用程序建立为“后台服务”。这将允许您的应用程序在用户继续使用另一个应用程序后继续发送数据。将 Cordova 应用程序建立为服务的说明位于:

    https://github.com/Red-Folder/bgs-core

    我会在此处包含实际说明,但这是一个相当漫长的过程,在这种情况下,我认为最有效和最有用的答案是提供指向包含说明的项目页面的链接。

    如果我能提供更多帮助,请告诉我。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      相关资源
      最近更新 更多