Apache Cordova plugin to record GPS positions in a background service on android
Java JavaScript
Latest commit 1a73d2d Dec 29, 2015 Bernd Oeggl feat: add getTrack for websocket
Permalink
Failed to load latest commit information.
docs Pass precision correctly in examples. Dec 1, 2014
src/android feat: add getTrack for websocket Dec 28, 2015
www Allow configuring more GPS parameters Dec 16, 2014
.gitignore add gitignore file Nov 17, 2014
LICENSE initial version for github repo Sep 19, 2013
README.md
TODO.md add and round bearing to returned json string Sep 14, 2015
plugin.xml feat: add getTrack for websocket Dec 28, 2015

README.md

cordova-plugin-gpstrack

Apache Cordova plugin to record GPS positions in a background service on android.

Usage

Javascript

var fileName = "/mnt/sdcard/mytrackfile_"+Date.now()+".json";
var precision = 30;   // GPS signal needs at least 30 meters precision
var tracker = new GPSTrack();

tracker.record(fileName, { precision: precision }, function(res) {
  console.log("GPStracker record: success for tracker");
}, function(err) { console.log("error on tracker"); } );
tracker.listen(function(succ) {
  // make sure websocket server has time to start up
  setTimeout(function() {
    setupWebSocket();
  }, 3000);
}, function(err) {
  console.log("GPStracker listen: error in listener "+err);
});

function setupWebSocket() {
  var ws = new WebSocket('ws://localhost:8887/snowhow');
  setTimeout(function() {
    if (ws.readyState === 1) {
      ws.send("getFilename");
    }
  }, 3000);
  ws.onmessage = function (evt) {
    var data;
    try {
      data = JSON.parse(evt.data);
    } catch (e) {
      console.log("illegal json data via websocket", evt.data);
    }
    handleWSResopnse(data);
  };
}

Uses cordova 3.0 plugin infrastructure, see http://cordova.apache.org/blog/releases/2013/07/23/cordova-3

Install this plugin from a command line like:

cordova plugin add https://github.com/snowhow/cordova-plugin-gpstrack.git

This plugin starts GPS recording as an android Service and therefore keeps running, even if android kills the main cordova application. Communication with Cordova Web-app is done via Websockets.