<script>
var URL = ["http://www.meteoxabia.com/estacions/port/mapa.htm", "http://www.meteoxabia.com/estacions/freginal/mapa.htm", "http://www.meteoxabia.com/estacions/valls/mapa.htm", "http://www.meteoxabia.com/estacions/lluca/wx11.html", "http://www.meteoxabia.com/estacions/castellans/mapa.htm", "http://www.meteoxabia.com/estacions/tosalgros/mapa.htm", "http://www.meteoxabia.com/estacions/capnao/wx11.html", "http://www.meteoxabia.com/estacions/poble/wx11.html", "http://www.meteoxabia.com/estacions/clubdegolf/mapa.htm", "http://www.meteoxabia.com/estacions/julians/wx11.html"];
var positions = [{
lat: 38.793625,
lng: 0.180238
}, {
lat: 38.783567,
lng: 0.166269
}, {
lat: 38.783402,
lng: 0.129075
}, {
lat: 38.761589,
lng: 0.148581
}, {
lat: 38.794598,
lng: 0.151655
}, {
lat: 38.749933,
lng: 0.119593
}, {
lat: 38.739241,
lng: 0.220552
}, {
lat: 38.790208,
lng: 0.162747
}, {
lat: 38.747097,
lng: 0.150225
}, {
lat: 38.777568,
lng: 0.110755
}];
var temperatures = new Array();
function getEstacio(URL, map, x, callback) {
// read text from URL location
var request = new XMLHttpRequest();
request.open('GET', URL, true);
request.send();
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status === 200) {
realtime = request.responseText;
realtime = realtime.split(" ");
if (realtime[1] == "") Marker(realtime[3].split("°C")[0], map, x);
else Marker(realtime[2].split("°C")[0], map, x);
callback();
}
}
}
var x = 0;
var getText = function(arr, map) {
getEstacio(URL[x], map, x, function() {
// set x to next item
console.log(x);
x++;
// any more items in array? continue loop
if (x < arr.length) {
getText(arr, map);
}
});
}
function getRealtime() {
console.log("getRealtime");
map = initMap();
console.log("Map: " + map);
getText(URL, map);
}
function initMap() {
console.log("initMap");
var uluru = {
lat: (38.7665732 + 38.773164) / 2,
lng: (0.050647 + 0.254409) / 2
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: uluru,
mapTypeId: 'hybrid'
});
return map;
}
function Marker(temperatura, map, x) {
temperatura = temperatura.substr(0, 4);
console.log("Marker" + " Temperatura: " + temperatura + "X: " + x);
var fecha = realtime[0] + ' ' + realtime[1]; //fentrada(var fecha);
var dia = fecha.substr(0, 2);
var mes = fecha.substr(3, 2);
var anno = fecha.substr(6, 2);
var hora = fecha.substr(9, 5);
var hora_datos = new Date(mes + '/' + dia + '/20' + anno + ' ' + hora).getTime();
var hora_actual = new Date().getTime();
var diferencia = hora_actual - hora_datos; // dada en milisegundos
if (diferencia > 360000) { // Lo he reducido a 6 minutos
// alert('la diferencia es mayor a 6 mn. y no muestro el marcador');
titleport = '';
iconport = '';
titlebarranquera = '';
iconbarranquera = '';
titlefreginal = '';
iconfreginal = '';
titlelluca = '';
iconlluca = '';
titlecastellans = '';
iconcastellans = '';
titletosalgros = '';
icontosalgros = '';
titlecapnao = '';
iconcapnao = '';
titlepoble = '';
iconpoble = '';
titleclubdegolf = '';
iconclubdegolf = '';
titlejulians = '';
iconjulians = '';
} else {
// alert('la diferencia es menor a 6 mn y muestro el marcador');
titleport = 'Port - Temperatura actual: ' + temperatura;
iconport = 'images/numeros/' + Math.round(temperatura) + '.png';
titlefreginal = 'Freginal - Temperatura actual: ' + temperatura;
iconfreginal = 'images/numeros/' + Math.round(temperatura) + '.png';
titlebarranquera = 'Barranquera - Temperatura actual: ' + temperatura;
iconbarranquera = 'images/numeros/' + Math.round(temperatura) + '.png';
titlelluca = 'Lluca - Temperatura actual: ' + temperatura;
iconlluca = 'images/numeros/' + Math.round(temperatura) + '.png';
titlecastellans = 'Castellans - Temperatura actual: ' + temperatura;
iconcastellans = 'images/numeros/' + Math.round(temperatura) + '.png';
titletosalgros = 'Tossal Gros - Temperatura actual: ' + temperatura;
icontosalgros = 'images/numeros/' + Math.round(temperatura) + '.png';
titlecapnao = 'Cap de la Nao - Temperatura actual: ' + temperatura;
iconcapnao = 'images/numeros/' + Math.round(temperatura) + '.png';
titlepoble = 'Xàbia - Temperatura actual: ' + temperatura;
iconpoble = 'images/numeros/' + Math.round(temperatura) + '.png';
titleclubdegolf = 'Xàbia - Temperatura actual: ' + temperatura;
iconclubdegolf = 'images/numeros/' + Math.round(temperatura) + '.png';
titlejulians = 'Xàbia - Temperatura actual: ' + temperatura;
iconjulians = 'images/numeros/' + Math.round(temperatura) + '.png';
}
//////// Y seguiríamos con el código normal.
// Tan solo ocultamos los iconos / marker que apareen los rojos de Google Maps
new google.maps.Marker({
position: positions[x],
map: map,
title: titleport,
icon: iconport,
title: titlefreginal,
icon: iconfreginal,
title: titlebarranquera,
icon: iconbarranquera,
title: titlelluca,
icon: iconlluca,
title: titlecastellans,
icon: iconcastellans,
title: titletosalgros,
icon: icontosalgros,
title: titlecapnao,
icon: iconcapnao,
title: titlepoble,
icon: iconpoble,
title: titleclubdegolf,
icon: iconclubdegolf,
title: titlejulians,
icon: iconjulians,
});
}
</script>