I am having an issue storing my location data for my journey tracking app. I am using both the accelerometer and GPS location in my app. All the data is being stored in the phones sqlite database. The sampling rate for the accelerometer is 25ms and 3000ms for the GPS. So for every 120 acceleromter readings I put into the database there is one GPS reading inserted.
This is working perfectly for about 30 seconds then the app strangely stops adding the GPS readings but it continues to add the accelerometer readings.
Below is my watch function that runs every 3 seconds taking readings from the GPS. The reason I am using this is because I was having issues previously with watch function for the plugin.
watch function code:
function watchLocation() {
var gcp = navigator.geolocation.getCurrentPosition(
// Success
function(position){
newlongitude = position.coords.longitude;
//alert("New "+newlongitude)
newlatitude = position.coords.latitude;
newSpeed = position.coords.speed;
//alert(position.coords.speed);
var timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
//alert(timestamp);
insertDB(track_id, newlongitude,newlatitude,newSpeed,timestamp,row);
row+=120;
},
// Error
function(error){
alert(error.message);
}, {
enableHighAccuracy: true
});
}
Below is the function I use to insert the GPS readings into my database. I use the sql update statement to update the row already created from the accelerometer reading with the GPS reading and the current compass heading direction.
InsertDB function code:
function insertDB(trackID, longi,lat,speed, time,arow){
//alert(Longi + " " + Lat);
watch_Comp = navigator.compass.getCurrentHeading(onSuccess, onError,compassOptions);
function onSuccess(heading) {
newDir = heading.magneticHeading;
//alert(newDir);
if(arow===0){
arow=1;
}
//alert("update row "+arow);
db.transaction(function(tx){
tx.executeSql('UPDATE DEMO SET longitude = '+'\''+longi+'\''+', latitude = '+'\''+lat+'\''+
', speed = '+'\''+speed+'\''+ ', time = '+'\''+time+'\''+', direction = '+'\''+newDir+'\''+
' WHERE uniqueID = ' + '\''+arow+'\'');
}, errorCB);
};
function onError(error) {
alert('CompassError: ' + error.code);
};
var compassOptions = {
frequency: 3000
};
Anyone have any idea what could be causing this to happen?
Aucun commentaire:
Enregistrer un commentaire