public
Created

Geovisualasation of Your Local Tweets

  • Download Gist
gistfile1.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
<!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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.