"google is not defined" when using Google Maps V3 in Firefox remotely

243,670

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> 

Solution 5

try this:

<script src="https://maps.googleapis.com/maps/api/js"></script>

it works for me... the point is, change HTTP to HTTPS

Share:
243,670
Traveling Tech Guy
Author by

Traveling Tech Guy

I'm a technologist, entrepreneur and developer. I started 3 startups, and currently assist other companies through Traveling Tech Guy - my software consulting company. I specialize in web and mobile development, integration projects, and managing software development projects of various sizes and complexities. I'm always looking for the next challenge, and always eager to learn a new technology/stack/paradigm. Most recently I've been using NodeJS, Express, React and various JavaScript frameworks. Prior to that, I developed in Scala, PHP, and several years of .Net in the enterprise. My mobile experience includes iOS, Android and WP. I've been an avid Stack Overflow user almost from day 1. I'm thankful to the community for helping me out of sticky code situations, and hope that I can contribute back by answering as many questions as I can - on Stack Overflow, Web Applications, Super User, and Android Enthusiasts.

Updated on August 04, 2021

Comments

  • Traveling Tech Guy
    Traveling Tech Guy almost 3 years

    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:

    1. Moved <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> to top of the <head> section.
    2. Moved all content of $(function() {...}); to a function called initialize() and added <body onload="initialize()">
    3. Played with scripts and css files order
    4. 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.