-
-
Save KennyLisc/336070 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" > | |
<head> | |
<title>Bing Maps</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
<script src="rx.js" type="text/javascript"></script> | |
<script src="json2.js" type="text/javascript"></script> | |
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> | |
<script type="text/javascript"> | |
var map = null; | |
jQuery.fn.ToObservable = function(eventType, eventData) { | |
return Rx.Observable.FromJQuery(this, eventType, eventData); | |
} | |
Array.prototype.toObservable = function() { | |
return Rx.Observable.FromArray(this); | |
}; | |
function searchTwitter(text) { | |
var url = | |
"http://search.twitter.com/search.json?rpp=100&q=" | |
+ encodeURIComponent(text); | |
return Rx.Observable.XmlHttpRequest(url); | |
} | |
function addPushPin( | |
id, | |
date, | |
latitude, | |
longitude, | |
imageUrl, | |
text, | |
details) { | |
try { | |
var pinPoint = | |
new VELatLong(latitude,longitude, 0, VEAltitudeMode. RelativeToGround); | |
var pin = new VEPushpin(id, pinPoint, imageUrl, text, date + " " + details); | |
map.AddPushpin(pin); | |
} catch(err) { | |
// Seen it, don't worry | |
} | |
} | |
$(document).ready(function() { | |
map = new VEMap("veMap"); | |
map.LoadMap(); | |
map.SetZoomLevel(2); | |
Rx.Observable | |
.Interval(10000) | |
.Select(function() { return searchTwitter("foursquare"); }) | |
.Switch() | |
.Select(function(result) { | |
return JSON.parse(result.responseText); }) | |
.SelectMany(function(data) { | |
return data.results.toObservable(); }) | |
.Where(function(data) { | |
return data.geo != null; }) | |
.Subscribe( | |
function(data) { | |
var lat = data.geo.coordinates[0]; | |
var lon = data.geo.coordinates[1]; | |
addPushPin( | |
data.id, | |
data.created_at, | |
lat, | |
lon, | |
data.profile_image_url, | |
data.from_user, | |
data.text); | |
}, | |
function(error) { | |
alert(error); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="veMap" style="position:relative; width: 1000px; height: 600px;"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment