ist_lion
ist_lion

Reputation: 3209

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>

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>

Upvotes: 1

Views: 1611

Answers (1)

Fraser
Fraser

Reputation: 17039

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

Upvotes: 3

Related Questions