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

前端 未结 14 2087
太阳男子
太阳男子 2020-12-01 10:28

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

相关标签:
14条回答
  • 2020-12-01 10:56

    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>
    
    0 讨论(0)
  • 2020-12-01 10:58

    I don't know for sure but here are my best suggestions.

    You're using jQuery. So instead of setting the event you should really be using $(function() {... }); to do your initialization. The reason to use this is that it ensures that all the scripts on the page have loaded and you're not limited to just one init function like you are with the onload body tag.

    Also, be sure your Javascript code is after the Google include. Otherwise your code might execute before the Google objects are created.

    I would also suggest taking a look at this page about event order.

    http://dean.edwards.name/weblog/2005/09/busted/

    0 讨论(0)
提交回复
热议问题