Created
October 31, 2011 12:53
-
-
Save nhunzaker/1327437 to your computer and use it in GitHub Desktop.
Article - 1 Twittermap Model and Collection
This file contains hidden or 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
// 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