GoogleEarth API Information

866 views
Skip to first unread message

xav

unread,
Nov 18, 2005, 1:04:10 AM11/18/05
to KML Discussions
For all who experiment with the GE API, here is some information I copied out of the VBA Object Browser of Excel.
I post it here in the KML forum, as there is no "Developer" or "API" forum.
The examples work with my GE Plus, you don't need Pro.

Eamples how to use the API with JavaScript in IE can be found HERE and HERE .
If anyone has additional Inforation about the API and how to use the methods, it would be nice if he/she would post it to this thread.

WARNING:
This interface is highly experimental, and is in no way supported by Google. It may be changed or omitted in future or final versions.
So, don't invest any money or time, unless you are willing to lose your investment.


But if you want to experiment like me, have fun!

xav
Code:
GoogleEarth API
______________________________________________

Library KEYHOLELib
Keyhole 1.0 Type Library
____________________________
Class KHFeature
element of KEYHOLELib
KHFeature Class

Property hasView As Long
write protected
element of KEYHOLELib.KHFeature
property hasView

Property visibility As Long
element of KEYHOLELib.KHFeature
property visibility
____________________________
Class KHInterface
element of KEYHOLELib
KHInterface Class

Property autopilotSpeed As Double
element of KEYHOLELib.KHInterface
property autopilotSpeed

Function currentView(terrain As Long) As KHViewInfo
element of KEYHOLELib.KHInterface
property currentView

Property currentViewExtents As KHViewExtents
write protected
element of KEYHOLELib.KHInterface
property currentViewExtents

Function getFeatureByName(name As String) As KHFeature
element of KEYHOLELib.KHInterface
method getFeatureByName

Function getPointOnTerrainFromScreenCoords(screen_x As Double, screen_y As Double) As Double()
element of KEYHOLELib.KHInterface
method getPointOnTerrainFromScreenCoords

Sub LoadKml(kmlData As String)
element of KEYHOLELib.KHInterface
method LoadKml

Sub OpenFile(fileName As String)
element of KEYHOLELib.KHInterface
method OpenFile

Sub QuitApplication()
element of KEYHOLELib.KHInterface
method QuitApplication

Sub SaveScreenShot(fileName As String, quality As Long)
element of KEYHOLELib.KHInterface
method SaveScreenShot

Sub setFeatureView(feature As KHFeature, speed As Double)
element of KEYHOLELib.KHInterface
method setFeatureView

Sub SetRenderWindowSize(width As Long, height As Long)
element of KEYHOLELib.KHInterface
method SetRenderWindowSize

Sub setView(view As KHViewInfo, terrain As Long, speed As Double)
element of KEYHOLELib.KHInterface
method setView

Sub setViewParams(lat As Double, lon As Double, range As Double, tilt As Double, azimuth As Double, terrain As Long, speed As Double)
element of KEYHOLELib.KHInterface
method setViewParams

Property streamingProgressPercentage As Long
write protected
element of KEYHOLELib.KHInterface
property streamingProgressPercentage
____________________________
Class KHViewExtents
element of KEYHOLELib
KHViewExtents Class

Property east As Double
write protected
element of KEYHOLELib.KHViewExtents
property east

Property north As Double
write protected
element of KEYHOLELib.KHViewExtents
property north

Property south As Double
write protected
element of KEYHOLELib.KHViewExtents
property south

Property west As Double
write protected
element of KEYHOLELib.KHViewExtents
property west
____________________________
Class KHViewInfo
element of KEYHOLELib
KHViewInfo Class

Property azimuth As Double
element of KEYHOLELib.KHViewInfo
property azimuth

Property latitude As Double
element of KEYHOLELib.KHViewInfo
property latitude

Property longitude As Double
element of KEYHOLELib.KHViewInfo
property longitude

Property range As Double
element of KEYHOLELib.KHViewInfo
property range

Property tilt As Double
element of KEYHOLELib.KHViewInfo
property tilt

ink_polaroid

unread,
Nov 18, 2005, 5:39:30 AM11/18/05
to KML Discussions
FYI, this interface is highly experimental, and is in no way supported.

Also, it's not guaranteed to exist in any kind of stable state until we document it.

xav

unread,
Nov 18, 2005, 8:20:17 AM11/18/05
to KML Discussions
I know, but it's fun!

And even if it is changed in the final version, playing around with it gives you some feeling of what can be done with GE.

xav

HookEmHorns

unread,
Nov 18, 2005, 9:20:04 AM11/18/05
to KML Discussions
Quote:

FYI, this interface is highly experimental, and is in no way supported.

Also, it's not guaranteed to exist in any kind of stable state until we document it.



Good to know, but it still rocks!

Valery35

unread,
Nov 18, 2005, 10:39:59 AM11/18/05
to KML Discussions
Post deleted by Valery35

xav

unread,
Nov 18, 2005, 11:08:09 AM11/18/05
to KML Discussions
I guess Google is just setting up GoogleEarth as a new advertising platform.

So I'm looking forward to the release of ESRI's ArcGIS Explorer

xav

Valery35

unread,
Nov 18, 2005, 11:21:13 AM11/18/05
to KML Discussions

HookEmHorns

unread,
Nov 18, 2005, 4:30:37 PM11/18/05
to KML Discussions
Quote:

I guess Google is just setting up GoogleEarth as a new advertising platform.

So I'm looking forward to the release of ESRI's ArcGIS Explorer

xav



ArcGIS Explorer is going to be out in 2006, but any idea which quarter? GE blows away that MS product that recently came out, but I have a feeling ESRI could trump GE... we'll have to wait and see.

Valery35

unread,
Nov 18, 2005, 5:54:15 PM11/18/05
to KML Discussions
See also http://www.microsoft.com/downloads/detai...;displaylang=en
Oleview.exe: OLE/COM Object Viewer
Sample result see http://forums.tjworld.net/viewtopic.php?t=50


My questions on which while there is no answer look

http://bbs.keyhole.com/ubb/showthreaded.php/Cat/0/Number/199596/an/0/page/2#199596
Member of KEYHOLELib.KHInterface
method getPointOnTerrainFromScreenCoords
Function getPointOnTerrainFromScreenCoords( screen_x As Double, screen_y As Double) As Double()
What means parameters of this function?
What does it return?

http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/199594/an/0/page/1/vc/1
Member of KEYHOLELib.KHInterface
method SaveScreenShot

Sub SaveScreenShot(fileName As String, quality As Long )
What means parameter quality ?

xav

unread,
Nov 18, 2005, 9:52:57 PM11/18/05
to KML Discussions
Valery,

I tried SaveScreenShot
It saves a greyscale JPG, Quality is the JPEG quality, 2 is bad, 100 is good.
Try it yourself with different values for quality.
Here is the Code:
<html>
<head>
<script>
function ScreenShot() {
qual=quality.value;
googleEarth.SaveScreenShot("C:/tmp.jpg", qual);
pic.innerHTML="<img src=c:/tmp.jpg>"
}
</script>
</head>
<body>
<font face="Arial">
<b>GE Screenshot<br>
<object width=0 height=0 classid="clsid:AFD07A5E-3E20-4D77-825C-2F6D1A50BE5B" id="googleEarth" >
</object>
Quality (2 - 100?): </b><Input size=3 id=quality value=2>
<button onClick="ScreenShot()">make screenshot</button>
<hr>
<div id="pic" ></div>
<hr>
</font>
</body>
</html>


xav

Valery35

unread,
Nov 19, 2005, 4:27:07 AM11/19/05
to KML Discussions
I am not assured of it. Itself tried a cycle up to 10000. Result strange.

function ScreenShot(i)
.. SaveScreenShot( "C:/tmp"+i. ".jpg", qual ->i );

xav

unread,
Nov 23, 2005, 1:06:25 AM11/23/05
to KML Discussions
It seems that Google has changed the behaviour of the method SaveScreenShot in version .0762.
If you invoke the method more than ten times, youll get unuseable results, with very very poor quality. But after a couple of minutes, the next 10 screenshots will be ok again.

In the previous version you could do any number of screenshots with no problems.

xav

Valery35

unread,
Nov 23, 2005, 4:32:41 AM11/23/05
to KML Discussions
Tnx
Probably, here not a special delay - new work with a stream.
Perhaps, at you long refresh?
I have not noticed it.

HookEmHorns

unread,
Nov 23, 2005, 3:14:57 PM11/23/05
to KML Discussions
Quote:

It seems that Google has changed the behaviour of the method SaveScreenShot in version .0762.




It doesn't look like there are any new classes, functions, properties, etc. though. The first thing I do when GE is updated now is go to your post with all the old API info and check to see if the new stuff matches up with it at a coarse level.

Valery35

unread,
Nov 23, 2005, 4:06:08 PM11/23/05
to KML Discussions
Yes =)

xav

unread,
Nov 23, 2005, 5:39:08 PM11/23/05
to KML Discussions
You are right,

there are no new or deleted properties,methods etc.

But: the "SaveScreenShot" method now acts differently.

You can try it yourself. download and unzip the attachment. Start GE and start the unzippd HTA file (just doubleclick).
Then click the button "make screenshot" more than 10 times. The first 10 times it will be ok, afterwards youll get a JPEG with quality 1.
In the previous versions there was no degrading of the quality. You could take hundreds of screenshots with the same (good) quality.

And I think this information might be of use for people who use this method, like EarthPlot, who do some nice litte programs and obviously use the API.

xav
208677-screenshot.zip

kens

unread,
Nov 25, 2005, 8:58:42 PM11/25/05
to KML Discussions
I tried the code and the image came back in black and white. How about yours?

xav

unread,
Nov 25, 2005, 9:31:07 PM11/25/05
to KML Discussions
with SaveScreenShot you get greyscale images only (and in a very moderate JPG quality)

xav

Valery35

unread,
Nov 26, 2005, 9:04:42 AM11/26/05
to KML Discussions
imho progression of r g and b chanels.

To GE team.
How works parameters _quality_ ?
I and xav probably 20-120 Gb images have made.

cybarber

unread,
Nov 26, 2005, 10:00:51 PM11/26/05
to KML Discussions
Hi,

I looked up the Keyhole in Excel VBA as well and with the posts on the API in the BBS, I made up the following demo page.

My test page is online attached KML file contains the link to the webpage. It controls/animates by JScript and HTML+TIME, lat/lon, range,tilt,heading. Screendump with sequential filenames and closing/starting GE by script. One can control GE from a Google Maps page and send data between the two. Jan. 19th: The URL has changed and the demo now has more features.


William A Slabbekoorn aka Cybarber
212341-ControllingGEbyScriptandTIME.kml

Valery35

unread,
Feb 5, 2006, 4:02:24 PM2/5/06
to KML Discussions
It while best manual.

xav

unread,
Apr 28, 2006, 2:10:08 PM4/28/06
to KML Discussions
There was a warning from GE staff that this information may not stay valid.

Meanwhile GE long passed the state of Beta and the API information still seems to be valid

Anyone knows if Google will officially support the API?

xav

Valery35

unread,
Apr 28, 2006, 4:38:42 PM4/28/06
to KML Discussions
Quote:



Anyone knows if Google will officially support the API?

xav




For you it officially need? GE team nice to correct use GE API, all functions correct job. Near API uses also in SketchUp. IMHO if GE team change API then make near functions.

Maybe next step it is Ruby scripts in GE?
http://sketchup.google.com/support/bin/answer.py?answer=38583&topic=8790
It is IMHO only

Clipper75

unread,
May 18, 2006, 10:29:16 AM5/18/06
to KML Discussions
Okay, so how do I access the API? i.e. how do I access the library? What are the pertinent file names for the library?

Which Google Earth version do I need as a minimum?

What I'm looking to do is embed a Google Earth control in a VB .NET app. If someone could tell me the minimal GE version I need and where the library is I can take it from there.

Thanks.

McKnight

unread,
May 18, 2006, 4:02:00 PM5/18/06
to KML Discussions
>Will this be officially supported?
An API will eventually be supported- not sure if it will be this one.


>Okay, so how do I access the API? i.e. how do I access the library? What >are the pertinent file names for the library?
There is a COM Object registered when you install google earth.
Here's what I've been able to dig up on it:
my blog post

>Which Google Earth version do I need as a minimum?
It works with the free version, just upgrade to the latest.

>What I'm looking to do is embed a Google Earth control in a VB .NET >app. If someone could tell me the minimal GE version I need and where >the library is I can take it from there.
You can't do that. You can only automate the Google Earth app from another application and introspect some of its current attributes.

Valery35

unread,
May 18, 2006, 4:48:46 PM5/18/06
to KML Discussions
Good blog. In pdf doc authors include examples of all functions.

Clipper75

unread,
May 19, 2006, 6:41:35 AM5/19/06
to KML Discussions
Good info, thank you. And great blog too!

SexyPants

unread,
Jul 10, 2006, 3:48:40 PM7/10/06
to KML Discussions
4.0.1657 has some new members:


Sub getCurrentVersion(major As Long, minor As Long, build As Long, AppType As AppType)
Member of EARTHLib.KHInterface
method getCurrentVersion

Sub isClientInitialized(isInitialized As Long)
Member of EARTHLib.KHInterface
method isClientInitialized

Enum AppType
Member of EARTHLib
Const GE_EC = 0
Member of EARTHLib.__MIDL_IKHInterface_0001
Const GE_Free = 5
Member of EARTHLib.__MIDL_IKHInterface_0001
Const GE_LT = 3
Member of EARTHLib.__MIDL_IKHInterface_0001
Const GE_NV = 4
Member of EARTHLib.__MIDL_IKHInterface_0001
Const GE_Plus = 2
Member of EARTHLib.__MIDL_IKHInterface_0001
Const GE_Pro = 1
Member of EARTHLib.__MIDL_IKHInterface_0001
Const UNKNOWN = 255 (&HFF)
Member of EARTHLib.__MIDL_IKHInterface_0001


It is interesting to note that some of the properties show different types in different object browsers. For instance when using Visual Studio 2005 to browse KHFeature it shows both hasView() and visibility() as Integer, where in the VB 6.3 browser in Excel they show up as Long.

Baccardi

unread,
Jul 21, 2006, 9:36:37 AM7/21/06
to KML Discussions
Hi Community!

I just found a way to turn on/off the "built in" layers of Google Earth like "Roads" or "Terrain" with the API.

I dont know if it is new for you (but I hope so! *proud*) , but for me it took really a long time to find a solution.

So, here it comes:
To build a geomarketing Tool I'm playing around with VBA (ArcGIS) and the GE API.

To turn on/off the Terrain for example you can do sth like this:

Code:
  

Dim KH As Object
Set KH = CreateObject("Keyhole.KHInterface")

Dim Kfeat As Object
Set Kfeat = KH.getFeatureByName("Gelände")
'since I am "playing" with the german language version, for me it is "Gelände", so in the english version you would have to enter "Terrain" I think.

Kfeat.visibility = 1 'turn layer on
Kfeat.visibility = 0 'turn layer off




I didnt try all "built in layers", but I think the others should be no problem.

So, I hope I could help out someone!

greetings,

Stefan Löhr

PS: Thank you Google-Earth-Team! I'm loving it!!!

ti3209

unread,
Aug 28, 2006, 11:36:29 AM8/28/06
to KML Discussions
HI,
I have just install Google Earth 4 beta (free version 4.0.1693) and I could not find KHInterface COM from either Visual Studio .net or Excel Visual Basic Editor).??

Has google remove this API fro the free version?

Thanks.

Nusinov

unread,
Sep 14, 2006, 2:39:27 PM9/14/06
to KML Discussions
With the new version of Google Earth released (ver. 4.0.2080) there seems to be a new set of Classes in the API, (the class names seem to be similar to the previous ones but have a GE appended on the end instead of KH in the front). Anyway, could we get a run down of the new features maybe?

Nusinov

unread,
Sep 21, 2006, 10:15:23 AM9/21/06
to KML Discussions
Using the new API I want to call the function "ApplicationGE.OpenKMLFile" except that it takes an integer in addition to the String. Anyone know what this integer is for?

Edit: I'm going out on a limb and guessing that all of the "...GE" classes are meant to phase out and replace the "KH..." classes. That is, ApplicationGE is meant to replace KHInterface. Some missing methods that are in KHInterface that aren't in ApplicationGE are SetView and QuitApplication. Are these renamed in ApplicationGE? or are they gone?

Edit Again: Ok I figured out using the CameraInfoGE and "setCamera" is a replacement for KHViewInfo and SetView. Also Logout is similar to QuitApplication, although it just logs out of google's server I believe (makes the Earth disappear but doesn't close the program)

One More Edit: SetRenderWindowSize in KHInterface doesn't seem to have an analogous function in ApplicationGE. Also, has anyone gotten ShowDescriptionBalloon(FeatureGE) in ApplicationGE to work? I would assume this would force the placemark to display hits Description Balloon but nothing seems to happen. (I figured this out, it seems you have to have a <LookAt> tag specified for the feature you're attempting to show the balloon of and it works)

Forza_Juve

unread,
Sep 22, 2006, 3:12:50 AM9/22/06
to KML Discussions
Hi mates,

I am now working with GE 4 APIs in the javascript environment. As known, we need to port GE into the webpage as activeX control. What I am wondering is whether there is a change on the classid for GE 4. I can get KHInterface (old api) work well using GE 4 Pro on my webpage using javascript. But I have got no idea at all how to use ApplicationGE class in GE 4 in javascript.

Does anybody give me a clue about usage of GE 4 APIs, particularly for javascript? Thank you very much in advance!!!!

here is a snippet in my codes:

<object classid="clsid:AFD07A5E-3E20-4D77-825C-2F6D1A50BE5B" id="googleEarth">
</object>
--- this is the classid for GE 3, but it also works fine for GE 4 Pro I am using. Weird~

var viewInfo = googleEarth.currentView (1);
viewInfo.latitude = lat;
viewInfo.longitude = long;
viewInfo.range = range;
viewInfo.tilt = 0;
viewInfo.azimuth = 0;
googleEarth.setView(viewInfo, 1, 1 );
--- obviously, currentView() is a method for GE 3, but it works fine for GE 4, TOO~

BUT, when I used "googleEarth.IsInitialized()", it reported that this method is not supported. IsInitialized() is a method of ApplicationGE class.


Cheers,
Alex

Nusinov

unread,
Sep 22, 2006, 9:20:58 AM9/22/06
to KML Discussions
Yeah all of the old KH classes are still supported, you just can't use the new ApplicationGE functions since its a different class.

IsClientInitialized I believe is the function in KHInterface.

luca63

unread,
Nov 2, 2006, 11:45:26 AM11/2/06
to KML Discussions
the second parameter is suppressMessage flag
if 1 no error message while loading
Reply all
Reply to author
Forward
0 new messages