[英]load and read differents Json file using MathRandom()
how can I read and load differents Json files using JavaScript? 如何使用JavaScript读取和加载不同的Json文件? example: Json1, Json2, Json3, Json4 some loop thats load on different Json every 30s
示例:Json1,Json2,Json3,Json4一些循环,每30秒在不同的Json上加载一次
was trying and looking, how to make it but nothing works for me, any idea? 在尝试和寻找,如何做到,但对我没有任何帮助,任何想法?
wants to include in this code 想要包含在此代码中
function loadpoints() { function getData(){
$.getJSON('pointer.json', function(pointer) {
var latlngbounds = new google.maps.LatLngBounds();
$.each(pointer, function(index, ponto) {
//where its my data working
var marker = new google.maps.Marker({
position: new google.maps.LatLng(ponto.lat, ponto.lon),
title: ponto.activity,
icon: ponto.activity + '.png',
map: map
});
console.log("created marker " + marker.position)
});
setTimeout (getData, 3000); });
}
getData();
}
@Mojtaba
function genereteRamdon (min, max){
var arr=[];
while (arr.length<4){
var randomNumber = Math.floor(Math.random() * (max-min+!))+min;
found=false;
for (var i=0, i<arr.length; i++){
if (arr[1] = randomNumber){found=true; break}
}
return arr;
}
}
$.getJSON('pointer.json', function(pointer) {
var latlngbounds = new google.maps.LatLngBounds();
$.each(pointer, function(index, ponto) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(ponto.lat, ponto.lon),
title: ponto.activity,
icon: ponto.activity + '.png',
map: map
});
console.log("created marker " + marker.position)
}
It's not much clear what are you trying to get. 目前尚不清楚您想要得到什么。
I guess you want this: 我猜你想要这个:
function getData(){
$.getJSON('pointer.json', function(pointer) {
var latlngbounds = new google.maps.LatLngBounds();
$.each(pointer, function(index, ponto) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(ponto.lat, ponto.lon),
title: ponto.activity,
icon: ponto.activity + '.png',
map: map
});
console.log("created marker " + marker.position)
});
}
getData();
setInterval(getData, 30000);
solution :) 解决方案:)
this piece of code was looking for 这段代码正在寻找
var min=1; var max = 4 // max number off json
var random = Math.floor(Math.random()*max)+min; var jsonfile =
"pointer" + random.toString()+".json" //display one of the files
$.getJSON(jsonfile, function(pointer)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.