I am using Google Map API and CSV file to plot the data on the map. Now I want to update the CSV file using JavaScript, so that the plotted points can be shown as moving objects in the map. I have used an active-X object. It updates the CSV file in IE only. Here is the JavaScript code:
var test = [
"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0",
"2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0",
"2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"
];
function file() {
for(var i=0; i < test.length; i++) {
setTimeout(function() {
time(i);
}, 10000);
}
}
function time(i) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileLoc = "D:\\test.csv";
var file = fso.OpenTextFile(fileLoc, 2, true, 0);
file.writeline(test[i]);
file.Close();
alert('File created successfully at location: ' + fileLoc);
}
I need to update the data every 10 sec. I am approaching for the way to delete the existing latlong in CSV and put new latlong so the the object can be seen as a moving one.
I believe storing a file on client side is not considered secure as per the standards and therefore not allowed [1]
However per your use case :
CSV file to plot the data on the map....I need to update the data every 10 sec...to delete the existing latlong in CSV and put new latlong
You have this js var in your code
var test = [
"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0",
"2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0",
"2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"];
So instead you could try JS local storage [2], maybe something like this
//set in local storage
localStorage.setItem('test','"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0","2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0","2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"');
//retrieve from local storage
var test2= localStorage.getItem('test');
console.log(test2);
[1] How can I create a file for storage on the client side with JavaScript?
[2] https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With