Google Earth “ERR_CREATE_PLUGIN”

妖精的绣舞 提交于 2019-12-11 10:20:24

问题


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>

While this code does not:

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

回答1:


The reason that won't work is because jquery may load before the Google Earth API.

That is google.earth.createInstance() is getting called by jquery in $(document).ready() before google.load() has finished.

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


来源:https://stackoverflow.com/questions/19987747/google-earth-err-create-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!