Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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:

  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.

like image 431
Traveling Tech Guy Avatar asked Jul 12 '11 07:07

Traveling Tech Guy


People also ask

How do you fix Google is not defined?

In summary, it's always caused by trying to use the Google Maps API (or some other Google API) before it's loaded. This can be fixed by either changing up the import order, using something like jQuery to run your code after the whole page has loaded, or by making sure your browser isn't the problem.

Why is Google Maps not working on my website?

You may need to update your Google Maps app, connect to a stronger Wi-Fi signal, recalibrate the app, or check your location services. You can also reinstall the Google Maps app if it isn't working, or simply restart your iPhone or Android phone.

How do I get rid of this page Cannot load Google Maps correctly?

You can do that by accessing Application restrictions, then navigate to “HTTP referrers” then type in your domain's name. After making the necessary changes, click Save. Copy the API key because you will need it to get the map back on your website.


2 Answers

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

like image 89
user841019 Avatar answered Sep 30 '22 15:09

user841019


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> 
like image 20
Diego Pino Avatar answered Sep 30 '22 15:09

Diego Pino