We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Google Earth Control
Page Index Toggle Pages: 1
Google Earth Control (Read 3180 times)
Google Earth Control
Jan 31st, 2006, 6:45pm
 
//Cut and paste all into processing

//Written by Jan Humble <jch@Cs.Nott.AC.UK> for
//ECT <http://www.crg.cs.nott.ac.uk/~jym/ect/ect.php>
//Adapted for Processing by
//Stefan Rennick Egglestone <sre@Cs.Nott.AC.UK>
//Concept by Andy Boucher <a.boucher@gold.ac.uk> and
//Andy Law <a.law@gold.ac.uk>
//Thanks to Nicolas Villar <nvillar@gmail.com>
//Original references from //<http://stevemargetts.blogspot.com/2005/07/controling-google-earth-from-jscript.html>
//Google Earth
//<http://earth.google.com/downloads.html>

public double longitude = -69.90;
public double latitude = 18.5;
public double range = 300;
public double tilt = 46;
public double heading = 50;
public String googleEarthClient = "C:\\Program Files\\Google\\Google Earth\\GoogleEarth.exe";

void setup()
{
 try
 {
   File localFile = new File("google_earth.kml");
   FileWriter fos = new FileWriter(localFile);
   fos.write(getKML());
   fos.flush();
   fos.close();

   String command = googleEarthClient + " " + localFile.getCanonicalPath();

   System.out.println(command);

   Process proc = Runtime.getRuntime().exec(command);
 }
 catch(IOException e)
 {
   e.printStackTrace();
 }
}

String getKML()
{
 String kml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
   + "<kml xmlns=\"http://earth.google.com/kml/2.0\">"
   + "<Placemark>"
   + "<description>The Dominican Republic</description>"
   + "<name>Jan's House</name>"
   + "<LookAt>"
   + "<longitude>"
   + longitude
   + "</longitude>"
   + "<latitude>"
   + latitude
   + "</latitude>"
   + "<range>"
   + range
   + "</range>"
   + "<tilt>"
   + tilt
   + "</tilt>"
   + "<heading>"
   + heading
   + "</heading>"
   + "</LookAt>"
   + "<visibility>1</visibility>"
   + "<Style>"
   + "<IconStyle>"
   + "<Icon>"
   + "<href>root://icons/palette-3.png</href>"
   + "<x>96</x>"
   + "<y>160</y>"
   + "<w>32</w>"
   + "<h>32</h>"
   + "</Icon>"
   + "</IconStyle>"
   + "</Style>"
   + "<Point>"
   + "<extrude>1</extrude>"
   + "<altitudeMode>relativeToGround</altitudeMode>"
   + "<coordinates>"
   + longitude
   + ","
   + latitude
   + ",0</coordinates>"
   + "</Point>" + "</Placemark>" + "</kml>";
 return kml;
}

Re: Google Earth Control
Reply #1 - Apr 10th, 2006, 11:35am
 
How do I get this to work with OSX google earth i tried to change the
public String googleEarthClient = "/Applications/Google Earth.app";
but it doesn't work
Re: Google Earth Control
Reply #2 - Apr 10th, 2006, 1:45pm
 
.app files on the mac don't take options from the command line the way that windows exe files do. you may have more luck sending an "open document" appleevent to the .app with those parameters. you might google around a bit to see if anyone has tried this.
Re: Google Earth Control
Reply #3 - Apr 12th, 2006, 3:45pm
 
I believe you can use the "open" command, as in

Code:
open -a /Applications/Google\ Earth.app ./google_earth.kml 



Double check the manpage but I believe -a specifies the application to open the file with.
Re: Google Earth Control
Reply #4 - Mar 22nd, 2010, 4:48am
 
This is awesome piece of code.

I can control in real-time the navigation of google earth.

Re: Google Earth Control
Reply #5 - Mar 22nd, 2010, 5:30am
 
pretty old but interesting, thanks for bumping it up
Page Index Toggle Pages: 1