15

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
  • 3,223
  • 13
  • 44
  • 69

4 Answers4

32

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!

urig
  • 16,016
  • 26
  • 115
  • 184
Cute Bear
  • 3,223
  • 13
  • 44
  • 69
14

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> 
Marcelo
  • 9,387
  • 3
  • 35
  • 40
  • I changed the source like you said, but I still receive the same error :/ – Cute Bear Sep 04 '12 at 11:30
  • Are you able to load it directly in the browser, for example if you click here? : https://maps.googleapis.com/maps/api/js?sensor=false Does your server run behind a firewall? – Marcelo Sep 04 '12 at 13:23
  • I just noticed that in Google Chrome's Javascript console: it gives the following error: [blocked] The page at https://www.mypage.com/GoogleMapPage.aspx ran insecure content from http://maps.googleapis.com/maps/api/js?v=3.9&sensor=false. – Cute Bear Sep 05 '12 at 08:12
  • and yes Marcelo, I am able to load it. – Cute Bear Sep 05 '12 at 08:12
  • my links were fine. http -> https problem. [source](http://stackoverflow.com/questions/7309013/warning-the-page-index-html-ran-insecure-content) – Cute Bear Sep 05 '12 at 12:26
  • This works, but the sensor query param has now been deprecated. This link could simplify to //maps.googleapis.com/maps/api/js. – Blake Oct 10 '16 at 14:01
7

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>
Farab Alipanah
  • 351
  • 4
  • 2
  • 1
    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. – Amit Shah Apr 11 '19 at 11:24
1

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

Vardmev
  • 11
  • 2