Created
April 20, 2012 23:01
-
-
Save jorgepedret/2432506 to your computer and use it in GitHub Desktop.
Loading Google Maps API on demand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // main.js | |
| function loadGoogleMapsApi(){ | |
| if(typeof google === "undefined"){ | |
| var script = document.createElement("script"); | |
| script.src = "https://maps.google.com/maps/api/js?sensor=false&callback=loadGoogleMapsApiReady"; | |
| document.getElementsByTagName("head")[0].appendChild(script); | |
| } else { | |
| loadGoogleMapsApiReady(); | |
| } | |
| } | |
| function loadGoogleMapsApiReady(){ | |
| $("body").trigger("gmap_loaded"); | |
| } | |
| // other.js | |
| $("body").bind("gmap_loaded", function(){ | |
| alert("Google map is loaded and ready to be used!"); | |
| }); | |
| loadGoogleMapsApi(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment