Skip to content

Instantly share code, notes, and snippets.

@librarywebchic
Created January 6, 2011 17:10
Show Gist options
  • Save librarywebchic/768191 to your computer and use it in GitHub Desktop.
Save librarywebchic/768191 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");
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("/devnetDemos/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;
});
});
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') {
var locations = new Array();
$.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];
});
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>
@librarywebchic
Copy link
Author

I have a set of latitude and longitude.
Send that to the MapFAST web service to get back FAST headings for places near that location.
Take FAST Headings returned and use them to go get matching records in WorldCat.
Build an array with location name, latitude, longitude, and an HTML list of the matching records in WorldCat.

@librarywebchic
Copy link
Author

MapFAST JSON response returns a string that represents the FAST heading which needs to be send to the WorldCat Search JSON call in order to get back the WorldCat records

@dbs
Copy link

dbs commented Jan 6, 2011

  1. Moved the var declarations into global scope
  2. Used the count-up / count-down method jbrinley suggested to fire the alert only once all callbacks have finished

Wow, that formatting turned out horrible, lemme see if I have to fork this gist or somethin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment