I have a backbone.js model. I want to load google maps API javascript from that model's method. I don't want to load the script in head of the document.
I can use $.getScript() to load the js & then display the map? But when I specify the callback function http://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=TRUE&callback=initialize
I always get an error because I dont want to define a global js function initialize(). I want the callback method to be a same backbone.js model's method.
App = Backbone.Model.extend({
construct : function(),
displayMap : function()
{
$.getScript("http://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=TRU&callback=initialize", function(data, textStatus, jqxhr) {
console.log('Load was performed.');
});
},
initialize: function()
{
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
});
var App = new App();
App.displayMap();
App.googleMapsCallback = function() { //... }? - Alberto Zaccagni