谷歌地球“ERR_CREATE_PLUGIN”

Google Earth "ERR_CREATE_PLUGIN"

本文关键字:PLUGIN CREATE 谷歌地球 ERR      更新时间:2023-09-26

我遇到了一个奇怪的错误。 我正在尝试加载Google地球库,但是这样做时出现错误"ERR_CREATE_PLUGIN"

以下代码确实有效:

<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之前加载。

也就是说google.earth.createInstance() google.load()完成之前就被jquery$(document).ready()打电话。

为了确保在调用createInstance()之前正确加载所有内容 - 只需通过google.load()方法从Google加载器加载jquery和earth api即可。这样,您就可以使用 setOnLoadCallback 方法来了解何时一切准备就绪。即

<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...