Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Google Earth Automation

Status
Not open for further replies.

craigsboyd

IS-IT--Management
Nov 9, 2002
2,839
US
Well, I could have sworn there was a thread out on these forums about automating Google Earth that I answered yesterday, but I can't for the life of me find it now. In any event, here is some VFP code that shows a couple things you can do with Google Earth...

First Example
Code:
*!* Let's go look at the Statue of Liberty
KH = CreateObject("Keyhole.KHInterface")
View = KH.currentView(0)
View.latitude = 40.6892
View.longitude = -74.0445
View.azimuth = 30
View.range = 100
View.tilt = 20
KH.setView(View, 10, .5)

Second Example
(make sure to save the screen shot - don't close Google Earth, as it will close by itself after the screen shot is saved)
Code:
LOCAL lcPictName
KH = CreateObject("Keyhole.KHInterface")
*!* There has to be a better way to wait for it to
*!* initialize, StreamingProgressPercentage was no help
=INKEY(4,"H") && wait for Google Earth to finish initializing
KH.setViewParams(40.7485, -73.9865, 250, 45, 30, 0, .5)
?KH.streamingProgressPercentage
lcPictName = PUTFILE("Save Image?", SYS(2015) + ".jpg")
IF !EMPTY(lcPictName)
	KH.SaveScreenShot(lcPictName, 100)
	MESSAGEBOX("A Screen Shot of the Empire State Building was saved to: " + CHR(13) ;
		+ lcPictName, 64, "Saved Google Earth Image")
ENDIF
KH.QuitApplication()

boyd.gif

SweetPotato Software Website
My Blog
 

Craig,

You weren't dreaming. I saw the thread on Google Earth, including your code. I asked you what component or software you need to install in order to run your code. Obviously, you need something to allow it to instantiate the Keyhole.KHInterface class.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

Glad to hear I wasn't mistaken, guess the thread was deleted.

The KHInterface class is in the GoogleEarth.exe, so in order to run the code I've posted you'd need to have Google Earth installed. Once that's done, you can open GoogleEarth.exe in the object browser to see what all is available for Classes and PEMs.

boyd.gif

SweetPotato Software Website
My Blog
 
Craig,

Thanks for that. I see the basic version of Google Earth is free, and the higher versions carry a subscription charge (
Looks like it will be fun to explore. I just wish I could think of a good business use for it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike said:
Looks like it will be fun to explore. I just wish I could think of a good business use for it.

The following article lists a few ways that businesses are using Google Earth to provide enhanced services to their customers...

I think of a database that holds longitude and latitude information and the VFP application bringing up the location of the record they are currently on. I recently create an application for a client that had to do with construction. I could see something like this being used to bring up a proposed construction site in Google Earth which might prove useful to the user for a number of reasons. I can even see super-imposing the floor plans over the location given VFP's GDI+ features and that Google Earth allows an image to be generated. Then perhaps a report could be generated with this super-imposed image included.

The main drawback with Google Earth and others of the same ilk, is that the images are not all the same resolution, so sparsely populated areas may not be shown with acceptable detail (depending on the proposed use). However, large metropolitan areas are quite good.

boyd.gif

SweetPotato Software Website
My Blog
 

Craig,

I see what you mean. Thanks for the info.

I don't doubt there are lots of ways of putting GoogleEarth to use. When I said I couldn't think of a good business use for it, I guess I meant that I couldn't see a way of exploiting it in my own applications.

But now that I know it exists, I'll keep it in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Craig

I have an interest in several projects using maps etc. I've just tried your first code as an example but it didn't seem to show anything, just the globe.
Code:
*!* Let's go look at the Statue of Liberty
KH = CreateObject("Keyhole.KHInterface")
View = KH.currentView(0)
View.latitude = 40.6892
View.longitude = -74.0445
View.azimuth = 30
View.range = 100
View.tilt = 20
KH.setView(View, 10, .5)
Your next piece of code zoomed straight in and when prompted gave the image a random save name e.g. _1ro1367ts (we can change that) but I dont get an option to save as a JPG or other image file. Am I missing something?

Your second code:
Code:
LOCAL lcPictName
KH = CreateObject("Keyhole.KHInterface")
*!* There has to be a better way to wait for it to
*!* initialize, StreamingProgressPercentage was no help
=INKEY(4,"H") && wait for Google Earth to finish initializing
KH.setViewParams(40.7485, -73.9865, 250, 45, 30, 0, .5)
?KH.streamingProgressPercentage
lcPictName = PUTFILE("Save Image?", SYS(2015) + ".jpg")
IF !EMPTY(lcPictName)
    KH.SaveScreenShot(lcPictName, 100)
    MESSAGEBOX("A Screen Shot of the Empire State Building was saved to: " + CHR(13) ;
        + lcPictName, 64, "Saved Google Earth Image")
ENDIF
KH.QuitApplication()
This zoomed in really quick but I have a question on the coordinates and settings.

Not being an expert in this line, I'm guessing these are the settings that make it happen:

View = KH.currentView(0)
View.latitude = 40.6892
View.longitude = -74.0445
View.azimuth = 30
View.range = 100
View.tilt = 20


I've changed a few of these but cant get a "straight down look".

Also, what settings determines the zoom in speed for the particular location?

Good coding Craig

Lee


Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Lee said:
I've just tried your first code as an example but it didn't seem to show anything, just the globe
Fire up Google Earth and then run the example code after Google Earth is finished initializing. The problem is that unless Google Earth is initialized already the code won't do anything. That is the reason that I added the wait of 4 seconds using INKEY() to one of the later examples. Depending on the computer speed 4 seconds might not be enough. I didn't find a good way to tell if Google Earth was finished intializing.

Lee said:
...but I dont get an option to save as a JPG or other image file
The screen shot image that is produced by the SaveScreenShot method is a JPG.

Lee said:
I've changed a few of these but cant get a "straight down look".
The reason is that the satelite imagery is taken at an angle. The closest you can get is to set the tilt to 0. In the case of the setViewParams method this is the 4th parameter.

Lee said:
Also, what settings determines the zoom in speed for the particular location?
The speed is determined by the last parameter that is sent to either setView or setViewParams methods.

Lee said:
Not being an expert in this line, I'm guessing these are the settings that make it happen:
Each example I showed is separate. setViewParams is just a single method that does much the same as setting those different properties of the KHInterface object individually.

You can explore the different methods and properties either by using the Object Explorer or in the code you could put something like the following to enable intellisense...
Code:
Local KH as Keyhole.KHInterface
KH = CreateObject("Keyhole.KHInterface")
...right after that you should be able to type "KH." and intellisense will show up for you.

boyd.gif

SweetPotato Software Website
My Blog
 
Hi Craig

I knew there was something I forgot to ask. Is there a command line that can be inserted somewhere to include location?

At the moment we have:

View.latitude = 40.6892
View.longitude = -74.0445


I'm thinking this would be great if we had something like:

view.location="my street, somewhere"

Obviously, some additional code could then be set up to allow a user to enter a street name etc which could be assigned to a variable.

view.location=myvarname

Just a thought

Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top