-2

I have an array of object with static values. This array of the object is used in EON Map for real-time tracking. I want to add values in this array dynamically I mean using a loop from the database.

Please suggest me how can I put my dynamic values in this array?

var torchys = [
    {
        latlng: [30.370375, -97.756138]
    },
    {
        latlng: [30.323118, -97.739144]
    },
    {
        latlng: [30.302816, -97.699490]
    },
    {
        latlng: [30.293479, -97.742405]
    },
    {
        latlng: [30.250337, -97.754593]
    },
    {
        latlng: [30.236689, -97.762730]
    }
];
Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29
SHARVAN
  • 21
  • 2
  • 4
    what have you tried & why can't you use `push`? – brk Apr 02 '19 at 09:23
  • @brk actually i have to show real time Taxies on map. i have lat longs but i don't know how to put my dynamic lat long in this format. the given array working fine. – SHARVAN Apr 02 '19 at 09:25
  • If you want to do realtime mapping, you don't need to push new values into the array, just just need to publish the values to the channel that EON/PubNub is listening to. The array of static values is just for demo purposes IIRC. You can post to PubNub Support for more assistance and we can post answer back here, just include the SO link in your ticket to PN support. – Craig Conover Apr 02 '19 at 16:16

3 Answers3

0

You're probably looking for the push method. For example:

torchys.push({latlng: [30.370375, -97.756138]})
Karamell
  • 1,023
  • 9
  • 23
-1

@brk actually i have to show real time Taxies on map. i have lat longs but i don't know how to put my dynamic lat long in this format. the given array working fine.

Using torchys.push(...) should be fine in your case. I'm not sure what you exactly mean by using loop from database.

Nikolay
  • 456
  • 3
  • 5
  • I mean to say the latitude and longitude coming from database and i want to set lat lng in this array. – SHARVAN Apr 02 '19 at 10:57
-1

You can use this method to push the dynamic latlng value into array.

const newArray = [];
for(var i=0; i< 10; i++){
   newArray.push({latlng: [i, i+1]});
}
console.log(newArray);