Google地球"ERR_CREATE_PLUGIN" [英] Google Earth "ERR_CREATE_PLUGIN"
问题描述
我遇到了一个奇怪的错误.我正在尝试加载Google Earth库,但这样做时出现错误"ERR_CREATE_PLUGIN"
I've come across a weird error. I'm trying to load the Google Earth libraries but when doing so am getting the error "ERR_CREATE_PLUGIN"
以下代码可以正常工作:
The following code DOES work:
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("earth", "1");
var ge = null;
function init() {
google.earth.createInstance("map3d", initCallback, failureCallback);
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
}
function failureCallback(object) {
}
</script>
</head>
<body onload='init()' id='body'>
<center>
<div id='map3d'
style='border: 1px solid silver; height: 600px; width: 800px;'></div>
</center>
</body>
该代码不提供:
<script type="text/javascript">
google.load("earth", "1");
var ge = null;
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
}
function failureCallback(object) {
}
$(document).ready(function() {
google.earth.createInstance("map3d", initCallback, failureCallback);
});
</script>
推荐答案
不起作用的原因是因为jquery可能在Google Earth API之前加载.
The reason that won't work is because jquery may load before the Google Earth API.
在google.load()
完成之前,$(document).ready()
中的jquery
会调用google.earth.createInstance()
.
That is google.earth.createInstance()
is getting called by jquery
in $(document).ready()
before google.load()
has finished.
为确保在调用createInstance()
之前正确加载所有内容-只需从google.load()方法> Google loader .这样,您便可以使用setOnLoadCallback
方法知道何时一切就绪.即
To ensure everything is loaded correctly before calling createInstance()
- simply load both, jquery and the earth api, from the Google loader via the google.load()
method. That way you can then use the setOnLoadCallback
method to know when everything is ready. i.e.
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
google.load("earth", "1");
google.setOnLoadCallback(function() {
//Place init code here instead of $(document).ready()
google.earth.createInstance("map3d", initCallback, failureCallback);
});
// etc...
这篇关于Google地球"ERR_CREATE_PLUGIN"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!