Reputation: 4244
I read the following article on how to get Google Maps, and gmaps.js
to work with RequireJS. However, when I build my project, RequireJS is swapped with Almond. In the article above, it states that Almond will not work with the RequireJS async plugin. Without the async plugin, Google's dependencies are not loaded, and gmaps.js
throw an error.
Is there a way to work around the issue and still load Google maps code in a project that uses Almond rather than RequireJS?
Upvotes: 9
Views: 973
Reputation: 1060
Almond.js can't handle with asynchronous plugins. You may use jQuery.Deferred to load the libraries.
var googleMapsLoader = function(func, options) {
var defaults = {
"sensor" : "false",
"v" : "3",
"key" : "",
"language" : "pt",
"region" : "br",
"libraries": ""
};
$.when($.ajax({
type: "GET",
dataType: "script",
data: $.extend({}, defaults, options),
url: "https://maps.google.com/maps/api/js",
crossDomain: true
})).then(function() {
func();
});
};
/*
* Loading Google Maps API with $.Deferred.
*/
googleMapsLoader(function() {
// You may call your code here.
}, {
"libraries" : "geometry,places",
"v" : "3.7"
});
Look at this example using $.Deferred and Maplace.
Upvotes: 0
Reputation: 431
Yeah I'm finding this too. Dynamic libraries cannot be loaded it says. I guess you'll have to download it locally.
Upvotes: 1