Google Maps loading order
When we want to include the Google Maps API, we have to put it in HEAD for it to get loaded. The problem here is that if we have a subsequent library depending in this API, we have to 1) hardcode the library after the script API inside head and 2) also hardcode the function execution after that again in our template inside head.. In general all our scripts inside /client/ or anywhere will be always loaded before the scripts inside HEAD. The problem with that is we have to either count on external calls overcoming the meteor loader or polluting our templates with inline JS...
My question is, is there any best practice / suggestion for overcoming this correctly/cleanly? I've seen people mentioning doing it with Template.created but no concrete example on how to do so. I've also seen the Meteor.startup method but I don't know exactly when the code inside it is executed and if that can help my case.
Thanks
You can put Google Maps code in Meteor.startup function or write own controller function and use Backbone's routing as I did in game I'm writing: https://github.com/jagi/taboo
function ($item, params) {
var $map = $item.find('.map:first');
var run = function () {
var myLatlng = new google.maps.LatLng(params.latitude, params.longitude);
var myOptions = {
zoom: Math.round(21.0 * (parseFloat(params.zoom) / 100.0)),
center: myLatlng,
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($map.get(0), myOptions);
var contentString = params.description;
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker)
})
};
var load = function () {
$.getScript("http://www.google.com/jsapi", function () { /* Using jQuery to load script dynamically. */
google.load('maps', '3', {
callback: run,
other_params: 'sensor=false'
})
})
};
load();
}
@gkatsanos, I think Meteor.startup is what you want. It runs once all of the scripts on your page are loaded (your app, and anything in your