Query Current Location from Google Earth?
NOTE: Images with an icon next to them have been artificially shrunk to better fit your screen; click the icon to restore them, in place, to their regular size.

Does anyone know of a command-line method to fetch the location currently centered in the display of a running Google Earth? I have spent untold hours trying to figure this out, and have always come up with a blank. If I can find a small command-line program that spits out a latitude/longitue/altitude of the current center of the Google-Earth viewpoint, I can greatly enhance my geoencoding support plugin for Adobe Lightroom. I'm looking for solutions for both Windows and Mac, although they don't need to be the same.

I do know about the Win COM library, but I'm not a Windows developer and have no idea what to do with it.

I'd love to hear ideas (or receive source code... hint hint! 🙂 ) if anyone has them...


All 9 comments so far, oldest first...

Hi there; I use a mac and I use applescript for that. The Google Earth applescript dictionary is not very extensive, but you can get latitude and longitude just fine. The script reads the coordinates and writes them to a temporary text file, which I later read in the lua script. To execute the applescript from the lua script I use something like this:

exitOption = LrTasks.execute(“osascript ” .. _PLUGIN.path .. “/GoogleEarthKit.scpt ” .. _PLUGIN.path .. “/coords.tmp”)

The applescript itself:

 on run argv
	
	set coordinates to {lat:0, lon:0, alt:0, dis:0}
	--		set theLatitude to ""
	--		set theLongitude to ""
	--		set theDistance to ""
	
	tell window 1 of application "Google Earth"
		set theViewInfo to GetViewInfo
		set lat of coordinates to latitude of theViewInfo
		set lon of coordinates to longitude of theViewInfo
		set dis of coordinates to distance of theViewInfo
	end tell
	
	set coordsSerialized to lat of coordinates & " " & lon of coordinates as text
	
	set filePath to item 1 of argv as POSIX file
	
	set tempFile to filePath as file specification
	try
		open for access tempFile with write permission
		set eof of tempFile to 0
		write coordsSerialized to tempFile
		set eof of tempFile to length of coordsSerialized
		close access tempFile
	on error
		return "error"
	end try
	
end run

I’m not sure how the code will show up in the comment; should you need it as a file just let me know!

Greetings from Spain!

Thanks for the head start! I ended up using GetPointOnTerrain {0, 0} instead of GetViewInfo because I want to know what the user is looking at, not where they’re looking from, but this solves my needs on OSX(!). Thanks! —Jeffrey

— comment by Rober on April 26th, 2009 at 1:17am JST (8 years, 8 months ago) comment permalink

The Google Earth API has provisions for registering Event Listeners. An example provided just updates local variables every time the user clicks anywhere in the window. You could use that to grab the last clicked event. Granted, the API documentation I was looking at seems to be specific to embedding Google Earth in your browser. Hmm, maybe embed Google Earth right into your geoencode plugin? 😉

— comment by Ken on April 26th, 2009 at 2:04am JST (8 years, 8 months ago) comment permalink

I do not know if what you describe is possible and I also I do not know how you intend to use it in connection with yout Lightroom plugin so I can only offer this suggestion.

In Google Earth the user selects
‘View’ -> ‘Make this my start location’ and then
‘File’ -> ‘Save’ -> ‘Save My Places’

so that the

\Application Data\Google\GoogleEarth\myplaces.kml

is updated (unfortunately the .kml file is not updated instantly)

and within your plugin (perhaps in a separate task) chcek the .kml file for any change of
and within .

— comment by E Sarmas on April 26th, 2009 at 4:02am JST (8 years, 8 months ago) comment permalink

Hi Jeffrey,

I did a quick Google search, and looks like it is possible to get the lat/long coordinates from Google Earth.

A guy named David Tryse has a program called Google Earth Position that displays a pop-up window with the lat/long coordinates of the center of the current Google Earth view: http://david.tryse.net/googleearth/#programs, with a link to a place to download his program http://code.google.com/p/googleearth-autohotkey/

I’m not sure if he reveals his code in the above links, but you might wanna try asking him for any hints.

— comment by Charlie on April 26th, 2009 at 5:02am JST (8 years, 8 months ago) comment permalink

Hello,

I don’t know much about programming, but if you just want to copy the lat/lng of the current viewpoint, I think you can try Autohotkey.
With autohotkey
– find the windows of GoogleEarch
– send the shortcut for “New Placemark”: Ctr+Shift+P, it should open a dialog
– send 2 times the Tab key
– send Ctr+C
– send Tab key
– send Home key
– send Ctr+V
– send Ctr+A
– send Ctr+C

and you have the lat/lng in clipboard

— comment by AnhTu on April 26th, 2009 at 7:09am JST (8 years, 8 months ago) comment permalink

I don’t know if it can help but a user create a Google Map (not Google Earth) to recover the coordinates of the point clicked (which can be better than the center of viewpoint)

http://www.google.com/ig/directory?url=Webb.Howard%2Bfoobar%40gmail.com&type=authors

— comment by Florent Bouckenooghe on April 26th, 2009 at 2:17pm JST (8 years, 8 months ago) comment permalink

I hadn’t notice the GetPointOnTerrain function, I guess they extended the dictionary in the last version. I’ll be able to include the altitude now, so thanks to you as well!

— comment by Rober on April 27th, 2009 at 4:50am JST (8 years, 8 months ago) comment permalink

I was able to get it working for Windows, too… thanks for the pointers to AutoHotKey. Using the library from Google, I ended up using

   #SingleInstance force
   #NoEnv
   #NoTrayIcon
   #ErrorStdOut
   #Hotstring NoMouse
   #KeyHistory 0
   #UseHook Off
   #include _libGoogleEarth.ahk
   WS_Eval(theValue, "gePoint()")
   FileAppend,%theValue%,%1%
   ExitApp

as my script. Thanks for the help!

— comment by Jeffrey Friedl on April 27th, 2009 at 8:33am JST (8 years, 8 months ago) comment permalink

Depending on how the application works: Adding a network-link that refreshes every second will send the current coordinates (and the ll and tr-corner) to a webserver. That could well be localhost. You can send back a list of the images in the viewport, so the geo-tagged images also show up in earth.

Chris

That would be wonderful, but Lightroom doesn’t allow any network access other than “open this url”, “send this HTTP POST”, etc, so I can’t do anything as direct as talk to Earth directly. I do have plans for greater integration, but it’ll require some magic under the hood. (There’s already some amazing magic under the hood for many features of these plugins, but users generally don’t care about the mountains you had to move… either it works for them or it doesn’t (and they normally complain in either case 🙂 ) —Jeffrey

— comment by Chris Niekel on April 27th, 2009 at 2:45pm JST (8 years, 8 months ago) comment permalink
Leave a comment...


All comments are invisible to others until Jeffrey approves them.

Please mention what part of the world you're writing from, if you don't mind. It's always interesting to see where people are visiting from.


You can use basic HTML; be sure to close tags properly.

Subscribe without commenting