Thursday, December 20, 2007

Load map script dynamically

I posted a topic in google maps api group asking how to load a map script dynamically. Thanks to igloo that response this to my question. The Maps API can be loaded dynamically by creating script tag and append it to the head section of the html page. You can call your own function to run when the loading of the map is finished. Here is a sample code.


function loadScript(callbackName) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAA-O3c-Om9OcvXMOJXreXHAxQGj0PqsCtxKvarsoS-iqLdqZSKfxS27kJqGZajBjvuzOBLizi931BUow&async=2&callback=" + callbackName;
document.body.appendChild(script);
}


You can test here: http://gmaps-samples.googlecode.com/svn/trunk/dynamicloading/scriptappend.html

http://groups.google.com/group/Google-Maps-API/browse_thread/thread/a8bc1539889b5fd/62f173b55e9a2e29?lnk=gst&q=dynamic+loading#62f173b55e9a2e29

Subscribe in a Reader