﻿//var gMockGps = null;

function MockGps(delay) {

    this.delay = delay;
    this.id = null;
    this.callback = null;

//    var timestamp = 311040000000;
    var timestamp = null;
    var latitude = 44;
    var longitude = 4;
    var altitude = 1;
    var heading = 45;
    var speed = 8.3485746;
    var accuracy = 15;
    var signLat = Math.random();
    
    var that = this; 

    this.startGeolocationMock = function(callback) {
        this.callback = callback;
        this.id = setInterval(this.sendPosition, delay * 1000);
    }
    
    this.stopGeolocationMock = function() {
        clearInterval(this.id);
    }

    this.restartPosition = function () {
        timestamp = null;
        latitude = 44;
        longitude = 4;
        altitude = 1;
        heading = 45;
        speed = 8.3485746;
        accuracy = 15;
    }

    this.sendPosition = function () {
//        timestamp = new Date().getTime();
//        var position = new dbPosition(timestamp, latitude, longitude, altitude, heading, speed, accuracy);
//        that.callback(position);
//        var addLat = Math.random();
//        var addLong = Math.random();
//        var addAlt = Math.random();
//        var addSign1 = Math.random();
//        var addSign2 = Math.random();
//        (addSign2 > 0.5) ? longitude += 0.0001 * addLong : longitude -= 0.0001 * addLong;
//        (signLat > 0.5) ? latitude += 0.0001 * addLat : latitude -= 0.0001 * addLat;
//        if (addSign1 > 0.5) {
//            //latitude += 0.0001 * addLat;
//            altitude += addAlt * 2;
//            speed -= 1;
//        }
//        else {
//            //latitude -= 0.0001 * addLat;
//            altitude -= addAlt * 2;
//            speed += 1;
//        }
//        if (altitude > 2000) altitude = 1980;
//        else if (altitude < 0) altitude = 1;
//        if (speed > 20) speed = 20;
//        else if (speed < 0) speed = 0;

        //pour avoir toujours le même point de départ (tests Cuong)
        timestamp = new Date().getTime();
        var position = new dbPosition(timestamp, latitude, longitude, altitude, heading, speed, accuracy);
        that.callback(position);
        longitude += 0.0001;
        latitude += 0.0001;
    }
}
