Monday, October 23, 2006

Hacking Google Maps
Recently, I've been playing around with Google's Mapping API. The way in which you enable GoogleMaps on your website is by including a small snippet of code on your website which gives you access to all their Javascript functions. If you're familiar with Javascript then seeing a line like this isn't new for you:

<\script src="http://maps.google.com/maps?file=api&v=2&key=" type="text/javascript">

Same as usual, Right? Well the complication starts when you want to dynamically load this javascript. Since this line makes a request to Google everytime the browser loads it, I don't really want my page to load any slower if Google's website isn't working. To do this I first went to this site
Dynamically Loading
External JavaScript Files
which demonstates how to do dynamic javascript loading. Unfortunately, when I tried it with GoogleMaps, it didn't work. Furthermore, all my attempts to post questions to the GoogleMap's Google Group discussion board failed (my posts never showed up!). It wasn't until I ran the script debugger that I discovered that GoogleMaps is using their own function to load javascript, but their version doesn't support dynamic loading! To fix this, I had to create my own javascript proxy. It simply fetches the javascript from Google, then replaces their script loading function, with my dynamic version, and returns it to whoever requests it. Then in my webpage, I use another dynamic loading function to load the javascript coming from my proxy.

No comments: