0

device 1 details:

{
    "positions": [{
        "address": "1326 13 Cross Rd, Bengaluru, KA, IN",
        "protocol": "osmand",
        "fixTime": "2017-01-19T11:58:40.000+05:30",
        "deviceTime": "2017-01-19T11:58:40.000+05:30",
        "latitude": 12.9750062,
        "longitude": 77.63568398,
        "valid": true,
        "speed": 0.0,
        "outdated": false,
        "altitude": 808.0,
        "course": 0.0,
        "deviceId": 2,
        "id": 545,
        "attributes": {
            "battery": "62.0",
            "ip": "192.168.0.107",
            "distance": 0.13,
            "totalDistance": 3307.1
        }
    }]
}

device 2 details :

{
    "positions": [{
            "address": "1326 13 Cross Rd, Bengaluru, KA, IN",
            "protocol": "osmand",
            "fixTime": "2017-01-18T17:38:29.000+05:30",
            "deviceTime": "2017-01-18T17:38:29.000+05:30",
            "latitude": 12.9750375,
            "longitude": 77.6356692,
            "serverTime": "2017-01-18T17:38:31.000+05:30",
            "valid": true,
            "speed": 0.0,
            "outdated": false,
            "altitude": 0.0,
            "course": 0.0,
            "deviceId": 1,
            "id": 262,
            "attributes": {
                "battery": "55.0",
                "ip": "192.168.0.108",
                "distance": 0.0,
                "totalDistance": 26.96
            }
        }

I need to store the position of these devices in separate stack simultaneously and to be fetched according to the device

function updateMapLive(positions) {
    for (i = 0; i < positions.length; i++) {
        console.log(positions[i].longitude + "," + positions[i].latitude);

        var latlong = positions[i].longitude + "," + positions[i].latitude;
        var deviceid = positions[i].deviceId;
        var Q = new Queue();

        Q.enqueue(latlong);
        arr.push(latlong);

        console.log(deviceid);
    }
}

function Queue() {
    this.stac = new Array();

    this.dequeue = function () {
        return this.stac.pop();
    }

    this.enqueue = function (item) {
        this.stac.unshift(item);
    }
}
Andreas
  • 21,535
  • 7
  • 47
  • 56

1 Answers1

0
  1. array.splice() is the thing you are looking for. Use this instead of unshift & pop. Read here to enqueue use this & to dequeue use this.
Community
  • 1
  • 1
psycho
  • 102
  • 8