Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将我的phonegap cordova gps跟踪系统启动或作为服务使用_Android_Cordova_Gps_Phonegap Plugins_Tracking - Fatal编程技术网

Android 将我的phonegap cordova gps跟踪系统启动或作为服务使用

Android 将我的phonegap cordova gps跟踪系统启动或作为服务使用,android,cordova,gps,phonegap-plugins,tracking,Android,Cordova,Gps,Phonegap Plugins,Tracking,我有一个android phonegap cordova gps跟踪系统,它根据cordova应用程序php文件上的数据库(名称、用户和密码)将位置发送到远程服务器数据库 服务器端由php编写,可以 我的问题是,若我回到应用程序,它会停止发送位置,因为它在后台不工作 我的问题是: 如何以一种简单的方式将我的应用程序启动或作为后台服务 请一步一步地告诉我我不专业:-)背景科尔多瓦地理位置: 您首先需要做的是,您需要添加一个,它可以帮助您完成需要在应用程序中添加的服务 使用插件 该插件使用以下方

我有一个android phonegap cordova gps跟踪系统,它根据cordova应用程序php文件上的数据库(名称、用户和密码)将位置发送到远程服务器数据库

  • 服务器端由php编写,可以
  • 我的问题是,若我回到应用程序,它会停止发送位置,因为它在后台不工作
我的问题是:

如何以一种简单的方式将我的应用程序启动或作为后台服务
请一步一步地告诉我我不专业:-)

背景科尔多瓦地理位置:

您首先需要做的是,您需要添加一个,它可以帮助您完成需要在应用程序中添加的服务

使用插件

该插件使用以下方法创建对象window.plugins.backgroundGeoLocation

configure(success, fail, option),

start(success, fail)

stop(success, fail).
安装插件:

cordova插件添加 阿东!如果不使用Cordova 5.x,则必须使用标记的分支#Cordova-4.x来安装插件,如下所示(因为Cordova已迁移到npm)

cordova插件添加 一个完整的例子可以是:

//
//
// after deviceready
//
//

// Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation,
//  in order to prompt the user for Location permission.
window.navigator.geolocation.getCurrentPosition(function(location) {
    console.log('Location from Phonegap');
});

var bgGeo = window.plugins.backgroundGeoLocation;

/**
* This would be your own callback for Ajax-requests after POSTing background geolocation to your server.
*/
var yourAjaxCallback = function(response) {
    ////
    // IMPORTANT:  You must execute the #finish method here to inform the native plugin that you're finished,
    //  and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    //
    //
    bgGeo.finish();
};

/**
* This callback will be executed every time a geolocation is recorded in the background.
*/
var callbackFn = function(location) {
    console.log('[js] BackgroundGeoLocation callback:  ' + location.latitude + ',' + location.longitude);
    // Do your HTTP request here to POST location to your server.
    //
    //
    yourAjaxCallback.call(this);
};

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

// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
    url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY:  your server url to send locations to
    params: {
        auth_token: 'user_secret_auth_token',    //  <-- Android ONLY:  HTTP POST params sent to your server when persisting locations.
        foo: 'bar'                              //  <-- Android ONLY:  HTTP POST params sent to your server when persisting locations.
    },
    headers: {                                   // <-- Android ONLY:  Optional HTTP headers sent to your configured #url when persisting locations
        "X-Foo": "BAR"
    },
    desiredAccuracy: 10,
    stationaryRadius: 20,
    distanceFilter: 30,
    notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
    notificationText: 'ENABLED', // <-- android only, customize the text of the notification
    activityType: 'AutomotiveNavigation',
    debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
    stopOnTerminate: false // <-- enable this to clear background location settings when the app terminates
});

// Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
bgGeo.start();

// If you wish to turn OFF background-tracking, call the #stop method.
// bgGeo.stop()
有关更多信息,请单击以下链接:


干杯,快乐编码。

背景科尔多瓦地理位置:

您首先需要做的是,您需要添加一个,它可以帮助您完成需要在应用程序中添加的服务

使用插件

该插件使用以下方法创建对象window.plugins.backgroundGeoLocation

configure(success, fail, option),

start(success, fail)

stop(success, fail).
安装插件:

cordova插件添加 阿东!如果不使用Cordova 5.x,则必须使用标记的分支#Cordova-4.x来安装插件,如下所示(因为Cordova已迁移到npm)

cordova插件添加 一个完整的例子可以是:

//
//
// after deviceready
//
//

// Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation,
//  in order to prompt the user for Location permission.
window.navigator.geolocation.getCurrentPosition(function(location) {
    console.log('Location from Phonegap');
});

var bgGeo = window.plugins.backgroundGeoLocation;

/**
* This would be your own callback for Ajax-requests after POSTing background geolocation to your server.
*/
var yourAjaxCallback = function(response) {
    ////
    // IMPORTANT:  You must execute the #finish method here to inform the native plugin that you're finished,
    //  and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    //
    //
    bgGeo.finish();
};

/**
* This callback will be executed every time a geolocation is recorded in the background.
*/
var callbackFn = function(location) {
    console.log('[js] BackgroundGeoLocation callback:  ' + location.latitude + ',' + location.longitude);
    // Do your HTTP request here to POST location to your server.
    //
    //
    yourAjaxCallback.call(this);
};

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

// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
    url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY:  your server url to send locations to
    params: {
        auth_token: 'user_secret_auth_token',    //  <-- Android ONLY:  HTTP POST params sent to your server when persisting locations.
        foo: 'bar'                              //  <-- Android ONLY:  HTTP POST params sent to your server when persisting locations.
    },
    headers: {                                   // <-- Android ONLY:  Optional HTTP headers sent to your configured #url when persisting locations
        "X-Foo": "BAR"
    },
    desiredAccuracy: 10,
    stationaryRadius: 20,
    distanceFilter: 30,
    notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
    notificationText: 'ENABLED', // <-- android only, customize the text of the notification
    activityType: 'AutomotiveNavigation',
    debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
    stopOnTerminate: false // <-- enable this to clear background location settings when the app terminates
});

// Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
bgGeo.start();

// If you wish to turn OFF background-tracking, call the #stop method.
// bgGeo.stop()
有关更多信息,请单击以下链接:


干杯,快乐编码。

您必须编写本机代码,使用cordova无法实现这一点。在你开始思考之前,请阅读商店指南,并不是所有可以做的事情都可以在公共应用程序中使用。嗨,谢谢你的回答,你的意思是不能做,我必须重新开始@joerg。你必须编写本机代码,这在使用cordova时不起作用。在你开始思考之前,请阅读商店指南,并不是所有可以做的事情都可以在公共应用程序中使用。嗨,谢谢你的回复,你的意思是不能做,我必须重新开始@JoergHello,谢谢你的回复,我卡住了。。你能帮我找一个付费的服务来做这件事吗@NemoCheck在答案末尾的链接。你会找到解决方案嗨,非常感谢你,尼莫先生,我的意思是使用付费服务修改我的应用程序而不是购买新应用程序,我很难更改它,如果你能帮助我,请给我发送电子邮件,我会与你联系谢谢@NemoHello,谢谢你的回复,我被卡住了。。你能帮我找一个付费的服务来做这件事吗@NemoCheck在答案末尾的链接。你会找到解决方案嗨,非常感谢你,尼莫先生,我的意思是使用付费服务修改我的应用程序而不是购买新的应用程序,我很难更改它,如果你能帮我,请给我发送电子邮件,我会与你联系谢谢@Nemo