我很想用 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');
}