Jquery mobile 每分钟向服务器发送gps坐标

Jquery mobile 每分钟向服务器发送gps坐标,jquery-mobile,cordova,geolocation,gps,Jquery Mobile,Cordova,Geolocation,Gps,我正在用jQueryMobile构建一个PhoneGap应用程序。在我的应用程序中,我需要每4分钟向服务器发送一个用户当前地理位置GPS坐标。我该怎么做 这是我现在正在使用的代码,但它不发送任何数据。我如何修改它使其工作 document.addEventListener("deviceready", onDeviceReady, false); var watchID = null; // PhoneGap is ready // function onDeviceReady() {

我正在用jQueryMobile构建一个PhoneGap应用程序。在我的应用程序中,我需要每4分钟向服务器发送一个用户当前地理位置GPS坐标。我该怎么做

这是我现在正在使用的代码,但它不发送任何数据。我如何修改它使其工作

document.addEventListener("deviceready", onDeviceReady, false);

var watchID = null;

// PhoneGap is ready
//
function onDeviceReady() {
    // Update every 4 minute
    var options = { maximumAge: 240000, timeout: 5000, enableHighAccuracy: true };
    watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}

// onSuccess Geolocation
//
function onSuccess(position) {
   var lat = Position.coords.latitude;
    var lng = Position.coords.longitude;


    jQuery.ajax({
        type: "POST", 
        url:  serviceURL+"locationUpdate.php", 
        data: 'x='+lng+'&y='+lat,
        cache: false
    });
}

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

不要调用setInterval,而是让phonegap为您这样做

// onSuccess Callback
//   This method accepts a `Position` object, which contains the current GPS coordinates
//
function onSuccess(position) {
    var element = document.getElementById('geolocation');
    element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                    'Longitude: ' + position.coords.longitude     + '<br />' +
                    '<hr />'      + element.innerHTML;
}

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
      'message: ' + error.message + '\n');
}

// Options: retrieve the location every 3 seconds
//
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { frequency: 3000 });
//onSuccess回调
//此方法接受包含当前GPS坐标的“位置”对象
//
成功时的功能(位置){
var element=document.getElementById('geolocation');
element.innerHTML='Latitude:'+position.coords.Latitude+'
'+ '经度:'+position.coords.Longitude+'
'+ “
”+element.innerHTML; } //OneError回调接收PositionError对象 // 函数onError(错误){ 警报('code:'+error.code+'\n'+ '消息:'+error.message+'\n'); } //选项:每3秒检索一次位置 // var watchID=navigator.geolocation.watchPosition(onSuccess,onError,{frequency:3000});

我试图使用该代码,但它似乎无法更新mysql。你能看看我编辑过的代码吗?首先,试着找出问题所在。检查数据是否返回到您的成功javascript函数,以了解这是js还是php问题。@Oscar每4分钟发送一次数据会很快给电池充电吗?