A simple library mashup

At the Erewhon workshop in December we asked people to choose/suggest applications for geodata. One of the favourites was: “Find the nearest copy of a book from a reading list (bearing in mind which libraries you can use, and the opening hours of libraries)” so we decided to use this as an example of how we’d begin to use Oxpoints data to enhance other services.

Ingredients:

A library search results page

A library search results page

We couldn’t easily get hold of the patron data (i.e. which libraries a user has access to), and the opening hours looked fairly indigestible in their current form (see example); so we decided to leave these out of this mashup.

Method:

We boiled down the list of libraries until it was reduced to just a name and a code for each library, simply structured:

Library codes

Library codes

then we worked out how the libraries’ unique identifiers corresponded to ours, and mixed these into the Oxpoints data. A lot of the mixing had to be done by hand, but we’re talking about a comparatively small dataset, and humans are good at fuzzy matching.

Once these codes were in place, we could query Oxpoints by library code to get location data in consumable form: KML for a simple link to Google maps, or JSON for use with the Google Maps API. By using Greasemonkey to add a pinch of JavaScript to the library search results page, we could add a Google Maps link besides each library:

Map links

Map links

e.g. BLL Main Libr gets turned into http://maps.google.co.uk/?z=16&q=http://m.ox.ac.uk/oxpoints/Library/BLL+Main+Libr.kml

So far so good: this saves the user clicking through another couple of pages to the ‘information’ page for each individual library (which gives a street address, though not a map). But it doesn’t let the user compare library locations easily; clearly we had to show all the library locations on the same map, and if we were going to include any more information than just the basic location, we needed a bit more control over the display — which meant using the Maps API rather than the public Google Maps.

We built a fairly simple Perl/CGI script which, given a library code (or multiple codes), would generate an HTML/JavaScript page with a basic Google Map showing the locations on a map. This meant that we could upgrade our Greasemonkey script to provide a link to ‘show all these libraries on a map’, by simply stringing all the codes on the page together and passing them to the map script, e.g.:

http://m.ox.ac.uk/cgi-bin/oxmap.pl?codes=BLL+Main+Libr|BOD+L.+Camera ...

The next step was to pass the ‘availability’ information through to our map as well. A bit more JavaScript to pick out the various statuses for each book (‘Available’, ‘MISSING’, ‘DUE BACK [date]’, etc.) and a rough-and-ready lookup to convert these to colours (e.g. green for ‘Available’, ‘On shelf’; red for ‘MISSING’; orange for ‘Apply Staff’…) meant that we could tell the Maps API what colour to make the markers, and give a richer picture:

Locations of libraries and availability of books

Locations of libraries and availability of books

Just one thing missing: where are you? Time for a bit more magic from the Google labs: the Google Gears Geolocation API lets you get the user’s latitude and longitude (if they allow Gears to access this information). This allowed us to add a ‘you are here’ marker to our map:

'U' are here!

'U' are here!

Of course, for a real application there would be lots of better ways to get the user’s location (native GPS on mobile devices; on desktop machines, the ability to set your own location); the map links would be built in to the search results pages rather than scripted in with Greasemonkey; we’d have more information about the libraries the user was allowed to access and consumable feeds of library opening hours, so that ‘availability’ wasn’t just a simple lookup but a calculation based on all those factors… but nonetheless this quick prototype mashup shows how far it’s possible to get without any of these things.

Here’s the Greasemonkey script: http://www.oucs.ox.ac.uk/oxpoints/olismapall.user.js

One Response to A simple library mashup

  1. […] was interesting to see one of the early mashup examples on the Erewhon blog was a Simple Library mashup that allows you to “(f)ind the nearest copy of a book from a reading list” using the […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: