Created
April 18, 2012 02:55
-
-
Save tyrauber/2410776 to your computer and use it in GitHub Desktop.
Calls out to google and then get's legislators twitter addresses through project sunlight
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
<head> | |
<title>Stop Cyborg Security Week — a campaign from Fight for the Future</title> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | |
<script type="text/javascript" src="http://www.google.com/jsapi"></script> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<div id="container"> | |
<div id="header"> | |
<script type="text/javascript"> | |
function geoTest() { | |
var lat = false; | |
var lng= false; | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition( | |
function (position) { | |
var lat = position.coords.latitude; | |
var lng = position.coords.longitude; | |
}) | |
if (!lat && !lng && google.loader.ClientLocation) { | |
var lat = google.loader.ClientLocation.latitude; | |
var lng = google.loader.ClientLocation.longitude; | |
} | |
} | |
getCongress(lat, lng) | |
} | |
function getCongress(lat, lng){ | |
if(lat && lng){ | |
var url = "http://services.sunlightlabs.com/api/legislators.allForLatLong?apikey=077165503e104b34a726e55ee77b367a&latitude=" +lat+ "&longitude="+lng | |
} | |
var text = lat+" "+lng | |
document.write(text+"<br/>"+url); | |
$(document).ready(function() { | |
$.getJSON(url, function(data) { | |
//var items = []; | |
var options = ''; | |
$.each(data.response.legislators, function(i, legislator) { | |
if(legislator.legislator.twitter_id!=""){ | |
var twitter = legislator.legislator.twitter_id | |
var name = legislator.legislator.title+" "+legislator.legislator.firstname+" "+legislator.legislator.lastname | |
} | |
if(name && twitter){ | |
// items.push({"name":name,"twitter":twitter}) | |
options += '<option value="' + twitter + '">' + name + '</option>'; | |
} | |
}); | |
$("select#tweet_congress").html(options); | |
}); | |
}); | |
} | |
geoTest(); | |
</script> | |
<select id="tweet_congress" name="tweet_congress"></select> | |
<div id="log"></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment