Loading google maps v3 asynchronously/dynamically

1 minute read

Out Of Date Warning

This article was published on 12/12/2011, this means the content may be out of date or no longer relevant.
You should verify that the technical information in this article is still up to date before relying upon it for your own purposes.

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