/ / Previsioni del tempo da WOEID (usando YQL o rss) in javascript? - javascript, jquery, yql, meteo, yahoo-api

Previsioni del tempo da WOEID (usando YQL o rss) in javascript? - javascript, jquery, yql, meteo, yahoo-api

C'è un modo per ottenere le previsioni del tempo da woeid in javascript?

Ho provato a utilizzare il feed rss di yahoo, ma non ho potuto farlo funzionare, ecco il mio codice

    var url = "http://weather.yahooapis.com/forecastrss?w=" + encodeURIComponent("WOEID here");

$.ajax({
url: url,
dataType: "jsonp",
jsonpCallback: function(data) { console.log(data); },
success: function(data) { alert("success"); }
});

Eventuali suggerimenti?

risposte:

2 per risposta № 1

Ecco il modo più semplice per ottenere le informazioni che vuoi usando jQuery e YQL:

var woeid = "26355493";

var $url = "http://query.yahooapis.com/v1/public/yql?callback=?";

$.getJSON($url, {
q: "select * from xml where url=" +
""http://weather.yahooapis.com/forecastrss?w=" + woeid + """,
format: "json"
}, function (data) {
console.log(data.query.results.rss.channel);
}
);​

La query nella console YQL ...

Il codice JavaScript in jsfiddle ...


1 per risposta № 2

Apparentemente, l'API Meteo restituisce i suoi risultati in RSS formato, mentre la funzione li sta aspettando jsonp formato. Considerare l'utilizzo Yahoo! Pipes per prendere il tempo RSS nutrire per te, elaborarlo e restituirlo jsonp formato.

Ecco una pipa che fa qualcosa di simile:

http://pipes.yahoo.com/pipes/pipe.info?_id=4d160cd8ed9d6d78164213928a51507d


0 per risposta № 3

Come suggerito dal drago, ho creato un pipe Yahoo: ecco il mio codice completo; l'url nel codice è il pipe di Yahoo che ho creato.

$(function(){
var url = "http://pipes.yahoo.com/pipes/pipe.run?_id=e33143abd20b19a0173b3a4b479fa4d3&_render=json&w=YOURWOEIDHERE";

function createRequest() {
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
return null;
}
var request = createRequest();
request.open("GET", url, true);
request.onreadystatechange = callback;
request.send(null);

function callback() {
if(request.readyState != 4) { return }
Obj = $.parseJSON(request.responseText);
console.log(Obj);
}
});

Riferimenti:
Yahoo Pipe: http://pipes.yahoo.com/pipes/pipe.info?_id=e33143abd20b19a0173b3a4b479fa4d3
jQuery 1.5 - Etichetta non valida di errore JSON