Another suggestion that helped me:
Here is what happent to me => My script was working once in 3 time I was loading the page and the error was the «google is not defined».
My function using the google map was in my jQuery document's ready function
$(function(){
//Here was my logic
})
I simply added this code to make sure it works:
$(function(){
$(window).load(function(){
//Here is my logic now
});
});
It works like a charm. If you want more details on difference between document ready and window load, here is a great post about it: window.onload vs $(document).ready()
The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.
The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds functionality to the elements in the page doesn't have to wait for all content to load.