ReferenceError: google is not defined

98,923

Solution 1

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!

Solution 2

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> 

Solution 3

To me, with the new Google Maps API, simply this solution worked: Just omit "async defer" from the script provided by goolge:

<script async defer src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>

TO

<script src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>

Solution 4

i met this problem in the rails application.

request to googlemap was from http and https pages

and it solved:

= javascript_include_tag "//maps.google.com/maps/api/js?sensor=false"

if protocol not defined rails inserts automatic

Share:
98,923

Related videos on Youtube

Cute Bear
Author by

Cute Bear

Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?

Updated on July 16, 2022

Comments

  • Cute Bear
    Cute Bear almost 2 years

    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?

  • Cute Bear
    Cute Bear almost 12 years
    I changed the source like you said, but I still receive the same error :/
  • Marcelo
    Marcelo almost 12 years
    Are you able to load it directly in the browser, for example if you click here? : maps.googleapis.com/maps/api/js?sensor=false Does your server run behind a firewall?
  • Cute Bear
    Cute Bear almost 12 years
    I just noticed that in Google Chrome's Javascript console: it gives the following error: [blocked] The page at mypage.com/GoogleMapPage.aspx ran insecure content from maps.googleapis.com/maps/api/js?v=3.9&sensor=false.
  • Cute Bear
    Cute Bear almost 12 years
    and yes Marcelo, I am able to load it.
  • Cute Bear
    Cute Bear almost 12 years
    my links were fine. http -> https problem. source
  • Cute Bear
    Cute Bear about 8 years
    @ParthChavda, try using //maps.google.com/maps/api/js?sensor=false
  • Blake
    Blake over 7 years
    This works, but the sensor query param has now been deprecated. This link could simplify to //maps.googleapis.com/maps/api/js.
  • Amit Shah
    Amit Shah about 5 years
    your answer is correct but there should be some other work around. like instead of using document.ready, can we check for google variable to be check if ready.

Related