Loading google maps v3 asynchronously/dynamically

12th December 2011 – 153 words

If you want to load the GoogleMaps from Javascript, instead standard in-head-script-tag, you have to use a callback-function. Otherwise the maps is not loaded completly.

if (typeof google == "undefined") {
  // no success callback necessary, google can load our stuff-todo-function
} else {
   // if gmaps already loaded, we can just continue whatever else we want to do

This above snippet was used, to open up a googlemap in a modal/Lightbox-frame. In this way, GoogleMaps Javascript is only loaded, when the user really wants to see a map

Reposted from notes.it-jobs-und-stellen.de