简体   繁体   English

Google Maps V3异步给出错误

[英]Google Maps V3 async gives error

For a website I'm trying to load the Google Maps script async, because it makes some browser (Firefox) ignore scrolling before all the scripts are loaded from Google. 对于一个网站,我正在尝试异步加载Google Maps脚本,因为它会使某些浏览器(Firefox)在从Google加载所有脚本之前忽略滚动。

I looked at the google developers docs and used their script. 我看了看Google开发人员文档并使用了他们的脚本。 https://developers.google.com/maps/documentation/javascript/examples/map-simple-async works all perfect as long as you place it inside a <script> tag in your index.html. 只要将它放在index.html中的<script>标记内, https://developers.google.com/maps/documentation/javascript/examples/map-simple-async就能完美运行。

But when I place this code for example in my main.js file it isn't working anymore. 但是,例如,当我将此代码放在main.js文件中时,它不再起作用。 Example: http://jsfiddle.net/693xK/ 示例: http//jsfiddle.net/693xK/

Then I found this example on jsfiddle which seems to work: http://jsfiddle.net/doktormolle/7cu2F/ But over here the same problem. 然后,我在jsfiddle上发现了该示例,该示例似乎可以正常工作: http : //jsfiddle.net/doktormolle/7cu2F/但在这里存在相同的问题。 When I place it inside of my main.js file Google Maps isn't showing up. 将其放在main.js文件中时,不会显示Google Maps。 Everything is global. 一切都是全球性的。 I get the following error but I don't understand what to do about it. 我收到以下错误,但我不知道该怎么办。 I googled the error message but haven't had any luck. 我在错误消息中进行了搜索,但是还没有碰运气。

TypeError: window.initialize is not a function

You're missing to add width and height to your #map-canvas . 您缺少为#map-canvas添加宽度和高度的信息 Also I checked your fiddle, since you're using window.onload = loadScript; 我还检查了您的小提琴,因为您使用的是window.onload = loadScript; so wrap it in head ( left corner, under Frameworks & Extensions ) 因此,将其包装在头部( “框架和扩展”下的左上角

#map-canvas{
    width:500px;
    height:500px;
}

check this updated JSFiddle . 检查此更新的JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM