“Nearby art”: using the V&A API and geolocation

By: on July 16, 2010

A little while back, I was informed that the V&A had an API. To be honest, my first response to this was “why on earth?”. There’s been a few similar APIs coming out recently from organisations, with some sort of “build it and they’ll come” expectations i.e. expecting that all they have to do is provide the API and all us developers will automagically build them shiny apps for free. If you’re TfL, then this kinda works, but it’s not so true for a lot of places.

Having had this initial reaction, I still decided to dig through the documentation a bit, and spotted an interesting nugget – they’ll let you do geospatial searches. I’d been tinkering around with the idea of playing with this, especially for use with my shiny new Android phone, and I had an a idea for a little app to show you “nearby art” i.e. search with the V&A’s API for the nearest bit of art.

I did this mostly in Javascript, doing XMLHttpRequest’s for JSON chunks of the API. There’s also a block of Python code that needs to run on a server, but that’s entirely to get around the issues of XMLHttpRequest only allowing same-server requests. It first uses navigator.geoLocation (official spec, easier documentation) to get the user’s location, then does two V&A queries – the first to get a list of local objects, and the second to get more info on the first object.

One thing you have to be careful about is that this can break in various ways. The most obvious is a lack of navigator.geoLocation (any version of IE, and all not-latest versions of most other browsers), and another is if the user denies access to their location data. This does make navigator.geoLocation unsuitable for general use currently, but it’s a useful source of data when there is support.

The full app is over here and the source is here.

FacebookTwitterGoogle+

5 Comments

  1. Ciaran says:

    Interesting.

    So now I know that the nearest bit of art to me is 4.775901065130269 km away, and is apparently a black and white photo of a house. Perhaps some extra info, or a link to further data, would be a good idea. (Yes, “use the source and implement it yourself” is a perfectly valid response to this – I’m just commenting in case another response is “didn’t you see the great big flashing ‘more info’ button?”)

  2. Andy says:

    For me the “Nearest object is 0.02085829325148746 km away and is: ?

    (image url given as: http://media.vam.ac.uk/media/thira/collection_images//.jpg)

    Sounds like I am in danger of tripping over it, but I have no idea what it could be.

  3. Tom Parker says:

    Ciaran: I’ve just dug through some of their other stuff, made a few guesses about how they’re constructing URLs elsewhere, and made a “more info” link :-)

    Andy: Curious. That URL means that they haven’t sent you a valid object number. I’ve just added a hack to the code to dump the request data they’ve sent if that happens, and if you hit that again, please follow the instructions it gives you and mail me, and I’ll see what I can do…

  4. Ciaran says:

    Thanks Tom, that works a treat. For the record, the ‘work of art’ in question is not 4.7km away – it’s the subject of it that’s there. I guess that should have been obvious to me in the first place.

  5. Andy says:

    Hi Tom,
    My problem is caused by the fact that although I am in London, my browser location (on a corporate intranet) is reporting me in downtown New York. Why it is doing is another question.

    Your “More info” shows this:
    http://collections.vam.ac.uk/item/O227911/photograph-manhattan-new-york-downtown/

    Fair enough.

Post a comment

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>