Created
April 29, 2010 14:38
-
-
Save jwheare/383691 to your computer and use it in GitHub Desktop.
Get a lat long from a tweet, by first checking twitter geotags, then foursquare links
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
var d = document, | |
w = window, | |
k = d.getSelection, | |
x = d.selection, | |
ws = w.getSelection, | |
s = (ws ? ws() : (k) ? k() : (x ? x.createRange().text : 0)), | |
l = d.location, | |
e = encodeURIComponent; | |
var tweetId = /\d+$/.exec(l)[0]; | |
var tweetAPIUrl = "https://api.twitter.com/1/statuses/show.json?id=" + tweetId + "&callback=tweetData"; | |
var tweetText; | |
jsonP(tweetAPIUrl); | |
function jsonP(url) { | |
var script = document.createElement('script'); | |
script.setAttribute('src', url); | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
function tweetData(data) { | |
tweetText = data.text; | |
if (data.geo) { | |
latlong(data.geo.coordinates[0], data.geo.coordinates[1]); | |
} else { | |
var foursquareMatches = /http:\/\/4sq.com\/[^\s]+/.exec(data.text); | |
if (foursquareMatches) { | |
var yqlUrl = "http://query.yahooapis.com/v1/public/yql?q=select * from html where url=\"" + foursquareMatches[0] + "\"&format=json&diagnostics=true&callback=yqlData"; | |
jsonP(yqlUrl); | |
} | |
} | |
} | |
function yqlData(data) { | |
var venueId = /\d+$/.exec(data.query.diagnostics.redirect.content)[0]; | |
var venueAPIUrl = "http://api.foursquare.com/v1/venue.json?vid=" + venueId; | |
var veneYqlUrl = "http://query.yahooapis.com/v1/public/yql?q=select * from json where url=\"" + venueAPIUrl + "\"&format=json&callback=foursquareData"; | |
jsonP(veneYqlUrl); | |
} | |
function foursquareData(data) { | |
latlong(data.query.results.venue.geolat, data.query.results.venue.geolong); | |
} | |
function latlong(lat, lon) { | |
// do something with the coords | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment