Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: google is not defined

Tags:

google-maps

I use google map's api in my website to show couple of locations. Google Maps is working just fine in my local solution but not in my website. I changed this source

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.5&sensor=false"> </script>

to this one. and i again changed this

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>

with this one...

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"> </script>

Only thing it says: ReferenceError: google is not defined

Does anyone familiar with such problem?

like image 234
Cute Bear Avatar asked Sep 03 '12 13:09

Cute Bear


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.

What does undefined mean on Google?

If this error message appears while trying to access our map page, it means that Google is being blocked, either by the browser or the network.

Why this page can't load Google Maps correctly?

Unless a valid API key is present, the map will be displayed in a lower resolution and will have a watermark on it. If the credit card linked to the account is invalid or the number of free map views is surpassed, the "This Page Can't Load Google Maps Correctly" error will show up.

Where do I get Google map API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.


2 Answers

Owing to the fact that my website uses https for the connection, I can not use http://maps.google.com/maps/api/js?sensor=false. When I debug the whole page, this link says: Warning : The page index.html ran insecure content. so I made another search on google and came across to this question. so what basically causes a problem is not using https link in the source part so the correct link will be (for me)

https://maps.google.com/maps/api/js?sensor=false

now everything works just fine!

like image 193
Cute Bear Avatar answered Oct 21 '22 01:10

Cute Bear


That's an old URL. If you look at the examples from the documentation, almost all of them use:

 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
like image 33
Marcelo Avatar answered Oct 21 '22 02:10

Marcelo