Skip to content

Instantly share code, notes, and snippets.

@jareware
Created July 29, 2012 10:49
Show Gist options
  • Save jareware/3197529 to your computer and use it in GitHub Desktop.
Save jareware/3197529 to your computer and use it in GitHub Desktop.
Google Maps API async loading w/ require.js 2.0
// lib/google-maps-loader.js
define({
load: function(name, require, load, config) {
var callback = 'maps_loader_' + new Date().getTime();
window[callback] = function() {
load(window.google);
};
require([ 'http://maps.googleapis.com/maps/api/js?key=' + name + '&sensor=false&callback=' + callback ]);
}
});
// lib/google-maps.js
define([ 'lib/google-maps-loader!API_KEY_GOES_HERE' ], function(google) {
return google;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment