Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Created October 31, 2011 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhunzaker/1327437 to your computer and use it in GitHub Desktop.
Save nhunzaker/1327437 to your computer and use it in GitHub Desktop.
Article - 1 Twittermap Model and Collection
// Twitter Map
$(function() {
//-- Data ---------------------------------------------------------------------//
var Tweet = Backbone.Model;
var Tweets = Backbone.Collection.extend({
// The search url which will pull in all tweets 1000 miles from roughly the center of the United States
url: "http://search.twitter.com/search.json?callback=?&count=100&rpp=100&geocode=35.5,-100,1000mi",
// Filters information before it is passed into the collection
parse: function(response) {
// Filter all tweets without a specific geolocation
var filtered = _.filter(response.results, function(d) {
if (d.geo !== null) {
return true;
}
});
this.add(filtered);
},
initialize: function() {
// Search for more tweets every 2 seconds
setInterval(function() {
console.log("Fetching fresh data...");
tweets.fetch();
}, 2000)
this.fetch();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment