I have a function to create a Google Map along with some other logic to create markers, infowindows and enable some user interaction to control the map.
When using jQuery and WordPress, by default, the $ function is disabled for compatibility.
To overcome this, I have encapsulated all my JavaScript code inside the following block:
(function ($) {
function initMap() {
console.log("Initmap start");
map = new google.maps.Map(document.getElementById("dealer-map"), {
center: new google.maps.LatLng(54.583408, -4.125605),
zoom: 5
});
setMarkers(map);
}
//...other code
}(jQuery));
(Sorry, I'm not sure what the above would be known as, hence the title)
There is then a function callback within the Google Maps API code which calls the initMap();
function once the API has loaded, however this does not work. I attempt to call this manually via the Chrome developer console, but a receive:
ReferenceError: initMap is not defined
Is there any way around this? Or would it be easier to just enable the $ function?