So, I started looking into ways for deterministically loading Google Maps as there are certain sections of the application I work on where Google Maps is not needed. Looking at the Google Ajax APIs, this seems like the easiest way to load Google Maps (and other Google APIs for that matter):
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABCDEFG"></script>
...
google.load("maps", "2");
Adding plugd into the mix, you can also cut down on loading the Google Ajax API JavaScript using the addScript method:
dojo.addScript("http://www.google.com/jsapi?key=" + key, dojo.hitch(this, function() {
var mapsLoaded = function() {
dojo.publish("/gmaps/loaded", []);
}
var langArray = dojo.locale.split("-");
google.load("maps", "2", {"callback" : mapsLoaded, "language": langArray[0] + "_" + langArray[1].toUpperCase()});
}));
And code which depends on Google Maps being loaded should listen to the "/gmaps/loaded" topic before trying to access any Google Maps APIs.
No comments:
Post a Comment