Created
November 10, 2010 03:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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