Skip to content

Instantly share code, notes, and snippets.

@juggy
Created November 10, 2010 03:21
Show Gist options
  • Save juggy/670289 to your computer and use it in GitHub Desktop.
Save juggy/670289 to your computer and use it in GitHub Desktop.
Collect country codes, names and states from yahoo geolocation service with underscore.js and jquery
window.Countries = {};
$.ajax({
url: "http://where.yahooapis.com/v1/countries",
data: {appid: "5mCqm._V34HyJ7CniyiCQq.oi8LjlbUnJ1ge4X36P9bpyyao2ey7xvS.mBb1jcAf69AzoQ--", format: "json"},
dataType: "json",
success: function(data){
var countries = _.map(data.places.place, function(country){
return {"name": country.name, "url": country.uri};
})
_.map(countries, function(country){
$.ajax({
url: country.url,
dataType: "json",
data: {appid: "5mCqm._V34HyJ7CniyiCQq.oi8LjlbUnJ1ge4X36P9bpyyao2ey7xvS.mBb1jcAf69AzoQ--", format: "json"},
success: function(data){
Countries[data.place["country attrs"].code] = {name: country.name};
}
});
});
}
});
//Need a pause before
_.each(Countries, function(c, key){
console.log(key);
$.ajax({
url: "http://where.yahooapis.com/v1/states/" + key,
dataType: "json",
data: {appid: "5mCqm._V34HyJ7CniyiCQq.oi8LjlbUnJ1ge4X36P9bpyyao2ey7xvS.mBb1jcAf69AzoQ--", format: "json"},
success: function(data){
Countries[key]["states"] = _.map(data.places.place, function(s){
return s.name;
})
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment