Last active
December 9, 2016 09:43
-
-
Save tormjens/42b353293fe956fe17bc3fe28a7a6895 to your computer and use it in GitHub Desktop.
Simple Google Maps Async Loader Using Deferred Object (ES6/jQuery)
This file contains 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
export default function(ApiKey, libraries) { | |
var promise = jQuery.Deferred(); | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = 'http://maps.google.com/maps/api/js?key='+ApiKey; | |
if(libraries) | |
script.src += '&libraries='+ libraries | |
document.body.appendChild(script); | |
jQuery('body').addClass('google-maps-ready'); | |
var interval = setInterval(() => { | |
if(typeof window.google !== 'undefined' && typeof google.maps !== 'undefined') { | |
promise.resolve(); | |
clearInterval(interval); | |
} | |
}, 200)// succeed | |
return promise.promise(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment