Dynamically Loading Google Maps api's

Posted by ido on Stack Overflow See other posts from Stack Overflow or by ido
Published on 2009-09-09T09:53:18Z Indexed on 2010/04/15 20:33 UTC
Read the original article Hit count: 394

Filed under:
|

Hi, Im trying to load the google maps api's dynamically. I'm using the following code:

var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'http://www.google.com/jsapi?key=<MY_KEY>;
head.appendChild(script);

but when trying to create the map

map = new GMap2(document.getElementById("map"));

or

map = new google.maps.Map2(document.getElementById("map"));

I'm getting an error that google (or GMap2) is undefined.

© Stack Overflow or respective owner

Related posts about google-maps

Related posts about dynamically