我試圖做一個循環來從不同的城市獲取wheather條件並將它們顯示在googlemap中作爲標記。 如果我這樣做,我可以在同一時間得到一個:如何使用getJSON從feed進行多個調用
$.getJSON("http://free.worldweatheronline.com/feed/weather.ashx?q="+markers[0].lat+","+markers[0].lng+"&format=json" +"&num_of_days=1" + "&key=e678d973c7184412112807"+"&callback=?",function(jsonp){
$.each(jsonp.data.current_condition, function(i){
var time = this;
markerWeather[0] = new google.maps.Marker({
position: new google.maps.LatLng(markers[0].lat,markers[0].lng),
title: "Temp. " + markers[0].title + ": "+ time.temp_C + " grados",
map: mapa
});
});
});
如果我複製一切,改變數它與我的所有標記工作...問題是,如果我換了號碼,並把一個變量,而不是一個循環,它不工作..例如:
for(z=0; z<=5; z++){
$.getJSON("http://free.worldweatheronline.com/feed/weather.ashx?q="+markers[z].lat+","+markers[z].lng+"&format=json" +"&num_of_days=1" + "&key=e678d973c7184412112807"+"&callback=?",function(jsonp){
$.each(jsonp.data.current_condition, function(i){
var time = this;
markerWeather[0] = new google.maps.Marker({
position: new google.maps.LatLng(markers[z].lat,markers[z].lng),
title: "Temp. " + markers[z].title + ": "+ time.temp_C + " grados",
map: mapa
});
});
});
}
請幫助!對於英國人來說很抱歉。
PS:這是我的網頁:www.kanawogirusa.com.ar PS2:這裏是代碼map.js
厄爾尼諾指數日markerWeather ESTA SIEMPRE EN 0Cambiálo Z como menciona Tigraine。 Y si no,usas push:markerWeather.push(new g ...); –
當我在這裏複製代碼時,我忘了將z放在markerWeather中! – Emiliano
我認爲這是一個變量z的範圍問題..它就像函數內部一樣,它的值總是6 ......如果我把警報(z);它在整個循環中返回6。 – Emiliano