"google is not defined" when using Google Maps V3 in Firefox remotely
Here's my conundrum: I have a page that uses Google Maps V3 and jQuery. It all worked well locally in FF5, Chrome and Safari.
Once I uploaded to a web site, I get a "google is not defined" error on the first line that I try to use a google object
var defaultLocation = new google.maps.LatLng(lat, lng);
It only occurs in FF and only occurs remotely (i.e., if I load the file into FF locally, it works well). Chrome and Safari seem to be working great regardless, as is my Android and iPod browsers.
Here's what I tried so far:
- Moved
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
to top of the<head>
section. - Moved all content of
$(function() {...});
to a function calledinitialize()
and added<body onload="initialize()">
- Played with scripts and css files order
- Pasted the URL http://maps.google.com/maps/api/js?sensor=false into FF address box and verified I'm getting the legit script
But since this is only happening in FF on a remote machine and works well otherwise, I don't think it has anything to do with my code. Maybe the load order in FF5 is screwed. Maybe it prioritizes network resources differently than other browsers. I really do not know what to make of it at this point.
Any help is appreciated.
Guy
Update:
Just wanted to add the following fact: After trying the previous on a Mac, I tried FF5 in Windows, and have replicated the exact same behavior.
For good measure, I tried Pale Moon as well - same results. Chrome 14, Opera 11.50 and even frickin' IE9 (which wasn't included in the test plan) work. It just FF5, now on both Mac and Windows 7, that fails on that page.
Solution 1:
I faced 'google is not defined' several time. Probably Google Script has some problem not to be loaded well with FF-addon BTW. FF has restart option ( like window reboot ) Help > restart with Add-ons Disabled
Solution 2:
I had the same error "google is not defined" while using Gmap3. The problem was that I was including 'gmap3' before including 'google', so I reversed the order:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="/assets/gmap3.js?body=1" type="text/javascript"></script>
Solution 3:
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.
Solution 4:
Try using this:
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>