google.earth.createInstance is not a function

213 views
Skip to first unread message

Sergey Emantayev

unread,
Apr 15, 2009, 4:41:57 PM4/15/09
to KML Developer Support - Google Earth Plug-in, cyberleo...@gmail.com
Hi

I'm trying to use Google Earth API from XHTML document. I'm using FF3.
When the file extension is .xhtml, I get following error:

google.earth.createInstance is not a function

There is another exception printed in Error console:

Error: uncaught exception: Operation is not supported
(NS_ERROR_DOM_NOT_SUPPORTED_ERR)
Source File:
http://www.google.com/jsapi?key=ABQIAAAAI6LZmD-FqAZVeamTjScGYhR0dDjxwEiZwld2-1_s6au4o9PdThTNZavQNg3-bLYRiD8InUQfkpwJPg
Line: 20

Here is the problematic line:

k[v].d=function(a,b,c){if(c){var d;if(a=="script"){d=m.createElement
("script");d.type="text/javascript";d.src=b}else if(a=="css")
{d=m.createElement("link");d.type="text/
css";d.href=b;d.rel="stylesheet"}var f=m.getElementsByTagName("head")
[0];f||(f=m.body.parentNode.appendChild(m.createElement
("head")));f.appendChild(d)}else if(a=="script")m.write('<script
src="'+b+'" type="text/javascript"><\/script>');else a=="css"&&m.write
('<link href="'+b+'" type="text/css" rel="stylesheet"></link>')};

If I rename .xhtml to .html, everything is OK. See the sample file
below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- Google Earth initialization -->
<script type="text/javascript" src="http://www.google.com/jsapi?
key=ABQIAAAAI6LZmD-
FqAZVeamTjScGYhR0dDjxwEiZwld2-1_s6au4o9PdThTNZavQNg3-
bLYRiD8InUQfkpwJPg"> </script>
<script type="text/javascript">
//<![CDATA[
google.load("earth", "1");

var ge = null;

function geInit()
{
google.earth.createInstance("map3d", initCallback, failureCallback);
}

function initCallback(pluginInstance)
{
ge = pluginInstance;
ge.getWindow().setVisibility(true); // required!
}

function failureCallback(errorCode)
{
alert("Failure loading the Google Earth Plugin: " + errorCode);
}

//]]>
</script>
</head>

<body onload="geInit()">

<div id="map3d_container" style="border: 1px solid silver; height:
400px; width: 600px">
<div id="map3d" style="height: 100%;"></div>

</div>

</body>
</html>

barryhunter

unread,
Apr 15, 2009, 5:25:49 PM4/15/09
to KML Developer Support - Google Earth Plug-in
You cant use real xhtml and the API at the same time. The common
loader uses document.write to load the scripts, which is not supported
in .xhml.

You can serve xhtml with the standard html mimetype and a xhtml
doctype, which is close. (its effectivly what you doing calling the
file .html)


On Apr 15, 9:41 pm, Sergey Emantayev wrote:
> Hi
>
> I'm trying to use Google Earth API from XHTML document. I'm using FF3.
> When the file extension is .xhtml, I get following error:
>
> google.earth.createInstance is not a function
>
> There is another exception printed in Error console:
>
> Error: uncaught exception: Operation is not supported
> (NS_ERROR_DOM_NOT_SUPPORTED_ERR)
> Source File:http://www.google.com/jsapi?key=ABQIAAAAI6LZmD-FqAZVeamTjScGYhR0dDjxw...

barryhunter

unread,
Apr 15, 2009, 5:27:53 PM4/15/09
to KML Developer Support - Google Earth Plug-in
Ah, but I do have an idea to work around it.

You might able to load the Earth API via the Google Maps API, which
has an undocumented parameter "&async=2&callback=loadMap" which causes
it to load the codedifferently, you can then do a map.addMapType
(G_SATELLITE_3D_MAP);

disclaimer, its just an idea, no idea if it will work.

Sergey Emantayev

unread,
Apr 15, 2009, 5:41:25 PM4/15/09
to KML Developer Support - Google Earth Plug-in
Mmm, I see.
I really need XHTML to embed KML into the document with the <xml> tag.
I'll try another possibilities to do that.

Thank you!
Sergey

Sergey Emantayev

unread,
Apr 15, 2009, 5:42:08 PM4/15/09
to KML Developer Support - Google Earth Plug-in
Thanks, I will try that too.

Sergey

Sergey Emantayev

unread,
Apr 15, 2009, 6:02:51 PM4/15/09
to KML Developer Support - Google Earth Plug-in
Unfortunately Google Maps API has the same problem with xhtml...

Zorrion

unread,
Jul 27, 2012, 1:06:15 PM7/27/12
to google-earth-...@googlegroups.com
This is a pretty old thread but I solved this issue using faces tags vs. html tags

<h:form>
<h:head/>
<h:body/>
</h:form>

I was able to do document.write without issues as long as the .js was imported through src.

so I did <src="to my custom js">

then inside the custom js I did the document.writes of the various other srcs I need based on environment etc.
Reply all
Reply to author
Forward
0 new messages