Skip to content

Instantly share code, notes, and snippets.

@dbs
Forked from librarywebchic/map_javascript
Created January 6, 2011 18:24
Show Gist options
  • Save dbs/768297 to your computer and use it in GitHub Desktop.
Save dbs/768297 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Find Books Related to where you are</title>
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAtsEsZKvTMrabC2Wd7XITJhR_DDkFHwL5BSWO8LemKnbXoiPGUBSIGXXVgNcF9XgCIlUajQ7GxO7c2w"></script>
<script type="text/javascript">
google.load("maps", "3",{"other_params":"sensor=true"});
google.load("jquery", "1.4.4");
google.load("jqueryui", "1.8.7");
var locations = new Array();
var remaining = 0;
function getBooks(locations){
// for each loop through the locations and add related books and make sure they are hidden
$.each(locations, function(i, location) {
$.getJSON("http://www.librarywebchic.net/mashups/wc_dc_records.php?SearchType=srw.su&SearchString=" + location[3] + "&callback=?",
function(bookdata){
booklist = '<ul class="booklist" style="display:none;">';
if (bookdata.status == 'ok') {
$.each(bookdata.books, function(i,item){
booklist += '<li><a href="http://www.worldcat.org/oclc/' + item.oclcnumber + '">' + item.title + '</a></li>';
});
} else {
booklist += '<li>No matching results.</li>';
}
booklist += '</ul>';
// add booklist as new piece of array
locations[i][4] = booklist;
remaining--;
alert(remaining);
if (remaining == 0) {
alert(locations);
}
});
});
};
function OnLoad(){
//docs for client location - http://code.google.com/apis/ajax/documentation/#ClientLocation
var lat = 40.106104;
var lon = -83.114376;
//Ask MapFAST For related subject headings nearby
var fast_request = 'http://experimental.worldcat.org/mapfast/services?geo=' + lat + ',' + lon + ';radius=100000&crs=wgs84&mq=&sortby=distance&max-results=3&callback=?'
$.getJSON(fast_request, function (data) {
if (data.Status.code == '200') {
$.each(data.Placemark, function(i,item){
// need to spilt item.point.coordinates into lat and long
var coordinates = new Array();
coordinates = item.point.coordinates.split(',');
var latitude = coordinates[0];
var longitude = coordinates[1];
locations[i] = [item.name, latitude, longitude, item.ExtendedData[0].value];
remaining++;
});
getBooks(locations);
} else {
return false;
}
});
}
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body>
<div id="found"></div>
<div id="cantfindyou"></div>
<div id="map" style="width:710px;height:350px;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment