Google Earth COM API

something to play with

Page 1 of 1

6 Replies - 6869 Views - Last Post: 06 July 2010 - 09:00 AM Rate Topic: -----

#1 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Google Earth COM API

Posted 25 June 2009 - 06:58 AM

This is not really a tutorial or a snippet and not much to blog about so its really just a random bit of code -- but I thought maybe someone could do something with it.

Here is a tiny little example of how to use JACOB (JAva COm Bridge) to interact with Google Earth.

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Variant;
//Google Earth's class ID: 8097D7E9-DB9E-4AEF-9B28-61D82A1DF784

public class GoogleCOM {
	public static void main(String[] args) {
		ActiveXComponent axGE = new ActiveXComponent("clsid:8097D7E9-DB9E-4AEF-9B28-61D82A1DF784");

		if (axGE!=null) {
		Variant[] view = {
				new Variant((double)-20.173128), 	//lat
				new Variant((double)57.448592),	//long
				new Variant((double)150),//alt
				new Variant(1),			//altMode
				new Variant((double) 1000),			//range
				new Variant((double) 0),			//tilt
				new Variant((double) 0),	//Azmuth
				new Variant((double) .1)	//speed
		};
		axGE.invoke("SetCameraParams", view);
		} else {
			System.out.println("No Object");
		}	
	}
}


This will use GE's SetCameraParams function to make the camera fly to a small island off the coast of Madagascar. My initial goal was to make a basic Google Earth Java API by wrapping some of the COM API -- but since I didn't really have a need for it, the project never really lifted off. -- So I thought rather than just letting the bit of code rot away in a dusty corner of my HD I might share and see if any young java developer thinks interfacing with GE is fun.

To run the program you just have to add the jacob.jar to your classpath. And of course you must have Google Earth installed. The program will launch GE and fly to the location (which you can interrupt at any time with the mouse).

Is This A Good Question/Topic? 0
  • +

Replies To: Google Earth COM API

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Google Earth COM API

Posted 03 July 2010 - 09:03 AM

I wanted to capture a question that came to me VIA PM:

The Last Fighter, on 03 July 2010 - 07:16 AM, said:

Hello NickDMax

I need your help in something relating communicating java with Google earth.
But I do not want to be involved in importing libraries or so, just I want to open the Google Earth by java using system calls, then sending commands and arguments to it by cmd using system calls, too.

Have you any idea how to do so ?

Thanks for your time.



My reply:

Quote

I have only worked with Google Earth though the old COM API which requires an interface library (I used JACOB in my code)

One easy way to integrate with GE is to embed a browser and then use the GE plug-in and its Javascript API. That *should* work from java (I know many phone apps do it this way).


And this, "I do not want to be involved in importing libraries" -- look to do some interesting integrations with various programs you will often either need a library, or write your own. Java exists in the VM and it is VERY limited in what it can do with interacting with other applications (because it is isolated intentionally) -- if you want to interact with a program you will probably need a C/C++ interface, you can either write that for yourself in JNI, OR you can use a library - it is up to you, but I generally choose a library.

Was This Post Helpful? 0
  • +
  • -

#3 The Last Fighter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 01-May 08

Re: Google Earth COM API

Posted 03 July 2010 - 03:36 PM

Ok, I tried to import the library as you said, and I ran the program, but I got errors in running. That I think was because the class id of Google earth on my pc is surely different from yours, so my question is how can I know mine? (sorry for any stupid questions, but I am quiet new to those topics)

This post has been edited by The Last Fighter: 03 July 2010 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Google Earth COM API

Posted 04 July 2010 - 03:04 PM

Actually the class ID should be the same... Though it may have updated as newer version of GE have come out....

Ok I have tested this on a new computer with the latest version of Google earth and it works just fine with the above class id.

If you are using eclipse this is how you add the library to your project:

Window > Preferences > Java > Build Path > User Libraries -- Click new button

Give the library a name like JACOB_1.15

The select the library and press Add JARs

Navigate to where you places your jacob.jar (for me this was C:\JavaExtras\Jacob-1.15-M3\ ) and select jacob.jar

Expand jacob.jar in the tree and select "Native Library location" and click "Edit" and set this to the jacob directory (should contain some .dll files)

you can also take a moment to add in the Javadocs for the library (I always find this helpful).

Now right click on your project and select "build path > configure build path" and goto the "libraries" tab and click "Add library", select "user library" and press next, select the Jacob library you just created and press "Finish"
Was This Post Helpful? 0
  • +
  • -

#5 The Last Fighter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 01-May 08

Re: Google Earth COM API

Posted 05 July 2010 - 04:13 AM

I do not have Eclipse, I have netbeans...

Here is the output error:
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.15-M3-x86 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:184)
at com.jacob.com.JacobObject.<clinit>(JacobObject.java:108)
at googleearthtest.GoogleCOM.main(GoogleCOM.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


and I have included the library normally, first from tools-->libraries
the add new library then adding the jar file of the JACOB

Then R.click on the project, properties,libraries,add library then choosing the added one

then drag and drop dll files from library folder in nbproject folder


I do not know what is the cause of the error.

I have read on some site that for making G.earth ready to be called, I have to write a "C:\Program Files\Google\Google Earth\googleearth.exe" /RegServer somewhere, do you know about this ?
Was This Post Helpful? 0
  • +
  • -

#6 The Last Fighter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 01-May 08

Re: Google Earth COM API

Posted 05 July 2010 - 05:06 AM

Now it works !! I discovered the source of the error , and it was that I had to copy the dll files in windows directory


Thanks very much

But I still have question,
1-How do you know the new class id of google earth if it is changed ?
2-Does the same method used here works also with any other program?
If yes, how I can know the class id of this program ?
3-I knew the source of the problem, but I still do not understand what happened when I transferred the dll to windows folder

Than you again
Was This Post Helpful? 0
  • +
  • -

#7 audio21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-July 10

Re: Google Earth COM API

Posted 06 July 2010 - 09:00 AM

hi NickDMax,
thanks for pointing me here.
now since reading with select statement works perfectly well; writing params into system objects like into w32UserAccount doesnt.
I tried it with invoke(method, str, obj)
with setProps() and call()...but no success.
maybe you can help me here, any idea?

This post has been edited by audio21: 06 July 2010 - 09:02 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1