Skip to content

Instantly share code, notes, and snippets.

@felipepodesta
Forked from chico/gist:1039016
Created June 23, 2011 01:41
Show Gist options
  • Save felipepodesta/1041716 to your computer and use it in GitHub Desktop.
Save felipepodesta/1041716 to your computer and use it in GitHub Desktop.
Geovisualasation of Your Local Tweets
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps?file=api&amp;v=2" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://static.clientsection.co.uk/css/weddingify-example.css" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="http://static.clientsection.co.uk/css/weddingify-example-ie.css" /><![endif]-->
</head>
<body>
<div id="bg"><div id="map" class="map"></div></div>
<div class="tweets"><div id="tweetcount"></div></div>
<script type="text/javascript">
$(function () {
function mapView(mapId, latitude, longitude) {
var map;
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById(mapId));
var loc = new GLatLng(latitude, longitude);
map.addControl(new GSmallZoomControl());
map.setCenter(loc, 13);
}
return map;
}
function addMarker(map, latitude, longitude, html) {
var marker = new GMarker(new GLatLng(latitude, longitude));
map.addOverlay(marker);
GEvent.addListener(marker, "mouseover", function() {
marker.openInfoWindowHtml(html);
});
}
function displayTweets() {
var twitterUser = "insert your twitter username here";
$.ajax({
url:'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + twitterUser + '&count=200&include_rts=1&callback=?',
dataType: "jsonp",
success:function(data, textStatus, jqXHR) {
var count = 0;
var mostRecentGeo = [];
for (i = 0; i < data.length; i++) {
if (null != data[i].geo && null != data[i].geo.coordinates) {
count += 1;
var html = '<div class="market-item"><div class="avatar"><img src="' + data[i].user.profile_image_url + '" width="40"/></div><div class="message">' + data[i].text + '</div></div></div>';
addMarker(map, data[i].geo.coordinates[0], data[i].geo.coordinates[1], html);
mostRecentGeo[0] = data[i].geo.coordinates[0];
mostRecentGeo[1] = data[i].geo.coordinates[1];
}
}
if (mostRecentGeo.length == 2) {
map.setCenter(new GLatLng(mostRecentGeo[0], mostRecentGeo[1]), 13);
}
$('#tweetcount').html(count + "<span>local<br/>tweets</span>");
}
});
}
var map = mapView('map', 51.506433, -0.118286);
displayTweets();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment