June 29th, 2005


(no subject)

This evening I did the unthinkable - I wrote some code outside of work.

For a while I've seen google maps and greasemonkey (a firefox extension to run some javascript on webpages when they load) used together and apart to do funky things and have utilised but otherwise ignored them. With today's release of the google maps API I thought I'd have a look.

So, as a quick first project to get me started I wrote a greasemonkey script that will add a local map to the bottom of London OpenGuide pages with map coordinates on them.
The script is here - load it and then choose "Install User Scripts" from the firefox tools menu (if you have greasemonkey installed)). It was all a lot easier than I expected.

It looks something kinda like this:

It's currently a cheat, as instead of dynamically generating the google map on the OpenGuide page, it creates an IFrame and calls back to a php script on my site that generates the map page. This is for 2 reasons:

1) I didn't want to submit the london.openguides.org URL to google for them to give me an API key - they lock down access to the google maps API by directory and website (so I have 2 keys - one for cowfish.org.uk and one for cowfish.org.uk/maps) - as I don't know what they'd do with the URL. Over-paranoid? Probably.
2) I just spent the last 2 hours beating javascript in an attempt to make the map hideable using javascript and stylesheets. It didn't work, and I don't feel like playing with any more for now, especially when I think that it's going to be an arse to get the google maps api javascript functions to dynamically load. Maybe.

I did find a way to dynamically add, and probably change, javascript embedded in webpages at "runtime". Which was nice.

If you do have a try of my greasemonkey script, let me know. If you think of any cool things to do with greasemonkey or google maps or both, also let me know, as I have the imagination of an unimaginative person when trying to think up things to code.