如何使用cordova在后台使用应用程序检索和发送地理位置?

时间:2016-11-29 17:33:02

标签: android cordova

function onDeviceReady() {

    navigator.geolocation.watchPosition(onSuccess, onError);

    var callbackFn = function(location) {
    console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);

当应用程序关闭时,此获取代码不会发送位置。我也尝试了其他方法,但没有成功将位置数据发送到服务器。

    $.get('http://test.com/rotech/location.php?latitude=' + location.latitude);

    backgroundGeolocation.finish();
};

var failureFn = function(error) {
    console.log('BackgroundGeolocation error');
};


    backgroundGeolocation.configure(callbackFn, failureFn, {
    desiredAccuracy: 10,
    stationaryRadius: 20,
    distanceFilter: 30,
    interval: 60000
});


    backgroundGeolocation.start();
}

0 个答案:

没有答案