Currently, I am facing an issue with scope in my backbone single page app that incorporates Google Maps. Despite ensuring all scripts are included in the correct order, I am struggling to understand why I am unable to instantiate a Google Map object as a global property outside of a function. Below is a snippet of my view declaration that works:
Viewer.Views.PhotosMap = Backbone.View.extend({
el: $('#conteneurLoad'),
markersOld: {},
mapOptions: function() {
return {
center: new google.maps.LatLng(35.3152208011549, -70.40635300000008),
};
},...
and here is the failing version:
Viewer.Views.PhotosMap = Backbone.View.extend({
el: $('#conteneurLoad'),
markersOld: {},
mapOptions: {
center: new google.maps.LatLng(35.3152208011549, -70.40635300000008),
},...
Upon using the second version, I encounter a "google is undefined" error. Any clear explanation or solution would be greatly appreciated. Thanks.