Go Back  Xtreme Visual Basic Talk > General Discussion > Tech Discussions > How To Control Google Earth with VB 6


Reply
 
Thread Tools Display Modes
  #1  
Old 08-16-2007, 12:24 PM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default How To Control Google Earth with VB 6


I work in the aerospace industry as your basic "all purpose" engineer. At one point, I had to write a flight simulator to interface with and drive our avionics systems. One of the things I did when I wrote it was to attach it to Google Earth so I could use it as a visual reference (just seeing geo coordinates doesn't mean a whole lot to me).

I developed some pretty usefull classes out of this and thought I'd post them here for anyone else who might need to automate Google Earth. They have a pretty decently documented type library that's installed when you install Google Earth on your system, but it's rather limited and extremely quirky. Think of the classes I'm posting here as a collection of lessons learned.

Some of the code in here (such as clearing the temporary places folder or checking the binary for Camera support) was lifted from the following location:
http://www.fortotalrecall.com/GE%20interface.htm

Make sure you have the latest Google Earth installed before trying it. In some cases, I've seen where a previously installed version fails to launch. Every time this has occured, I've been able to fix the problem by reinstalling Google Earth (you only have to do this once, the problem is resolved after that).

Google Earth specific classes are as follows:

CGEarth:
Main interface to the Google Earth application and camera view.

CGEAircraft
This is an example KML object that I created to demonstrate how you can overlay icons and other graphical data in the GE window.

CGETrack
This is a list of track coordinates (which is used by CGEAircraft to construct its flight history path).

CGETrackPoint
A single flight history path coordinate point.

The CGEAircraft class is pretty configurable. Try messing around with settings like TrackColor, TrackWidth, DrawTrack, TrackType, DrawExtrudeLine, etc.

In this example, the Timer1_Timer event shows how you can add a point to CGEAircraft and then send that updated feature to GE:

Code:
AC.SetPoint 0, 0, AC.Longitude + 1, 10000
GE.AddFeature AC.FeatureName
You can also register the GE object as a parent of the aircraft class as follows (in the Form_Load event):

Code:
AC.RegisterGEParentApp GE
If you do that then any points you add to the aircraft class will automatically update in Google Earth without you having to explicitly send it the KML file.

Enjoy.
Attached Files
File Type: zip Google Earth.zip (21.1 KB, 1116 views)
__________________
http://www.joshuagayou.com
Reply With Quote
  #2  
Old 08-16-2007, 03:13 PM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

Upload of an example screenshot.
Attached Images
File Type: bmp example.bmp (1.75 MB, 485 views)
__________________
http://www.joshuagayou.com
Reply With Quote
  #3  
Old 08-17-2007, 10:02 AM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default Bug Fix

This is a one liner, so I'm not going to re-post the whole package. Just go to the m_PollTimer_Timer event in the CGEarth class and add the following line of code to the beginning of the sub (such that it is the first executed statement).

Code:
    Set m_Camera = m_App.GetCamera(True)
__________________
http://www.joshuagayou.com
Reply With Quote
  #4  
Old 03-27-2008, 07:14 PM
swdev swdev is offline
Newcomer
 
Join Date: Mar 2008
Posts: 7
Cool This is helpful

thanks.
I have an order of automating GE, but using VB.NET
I thought it is hard, but there are API interfaces

Great!
Your code should be helpful!

Any idea of converting it to VB.NET?
Reply With Quote
  #5  
Old 03-28-2008, 08:24 AM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

I actually have, but the problem is that I don't have it in any form that I can distribute out to the net yet. All the code I wrote for it is an integrated chunk of a library assembly that I wrote for my company, so I don't have any code that I can post without exposing a lot of our intellectual property.

I will say that the code that I wrote for .NET is very similar to the VB 6 variety. The biggest difference has to do with syntax between languages; the GE object itself is just something you can add to your project references as a COM object and any house keeping that I'm doing is mostly API calls.

I'll try to get a version of this together that I can distribute, but in the mean time, feel free to post any difficulties you have in your project and I'll see how I can help.
__________________
http://www.joshuagayou.com
Reply With Quote
  #6  
Old 04-07-2008, 02:32 PM
xtremedeniz xtremedeniz is offline
Newcomer
 
Join Date: Apr 2008
Posts: 2
Default altitude from GE

Hello,

Your code is perfect. I want to make a car simulation. I should give altitude of the ground not a fixed altitude. How can read current altitude of earth if i know lat/lon coordinates.

BR

Denis
Reply With Quote
  #7  
Old 04-07-2008, 04:56 PM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

Quote:
Originally Posted by xtremedeniz View Post
Hello,

Your code is perfect. I want to make a car simulation. I should give altitude of the ground not a fixed altitude. How can read current altitude of earth if i know lat/lon coordinates.

BR

Denis
Thanks.

There are two ways you can do this, both of which are unpretty.

The first method is to create a 1st person driving simulation.

In this case, unless they've fixed up the API in the latest release (which I haven't tested or played with yet) I think you're going to have a few problems outside of determining altitude.

I tried doing something similar to what you're looking at when I first wrote this code. So what I wanted to do was create a first person mode (like a flight simulator or pilot's view) but the problem is that they wrote the API with the intent of it being used for top-down Earth views. Because of this, you have a couple of problems:

1. There is no smooth way to transition the camera from point a to b in this situation. The movement of your transition is set by your camera transport speed. If you set it to teleport, you instantly jump to the new location, which is kind of disorienting if you're trying to simulate a smooth, 1st person view.

If you set the transport speed to anything higher than teleport, you get this annoying hop effect when traversing short distances. This is an artifact from when you transport from somewhere like California to somewhere like Egypt. In this case the camera pulls back from the Earth nice and smooth to give you a big wide shot as you fly over the surface of the globe and then closes back in to your destination. Looks really cool over a long distance; looks like hell over a short hop.

2. GE dictates that you control camera placement through several factors, only a couple of which are latitude and longitude. You also have to worry about azimuth (or heading), tilt, and distance. One of the factors that's going to cause you grief is Distance. The camera always automatically struggles to maintain its current distance from the focal point.

This works okay when looking straight down at the focal point, but when you tilt out fully, you'll notice a really stupid bug.

0 tilt means you're looking directly down at the Earth. Max tilt puts you horizontal to the ground looking out, but if the altitude of your focal point ever changes, your camera will adjust to maintain its current distance.

The worst part about this is that the Altitude track for the camera is judged to be extending out from the back of the camera, meaning that if your focal point raises in altitude and your camera is at full tilt, your camera will actually move backwards rather than lift higher off the ground (this is a bug in their API). It's easier if you look at the picture I've attached, which explains this better.

In the first series the camera is at 0 tilt. The focal point raises in altitude, so the camera automagically adjusts its distance to compensate. Not bad.

In the second series, the camera is at full tilt. the focal point raises in altitude, and the camera stupidly thinks that it can still maintain it's distance setting by moving backwards. Lame.

All of this means that not only are you going to have to know the elevation of each point on the map that you drive to (because this is a factor and it will be possible for you to disappear into the ground or become airborne), you will also have to decrease your distance setting from the focal point in proportion to any altitude gain and increase the distance setting from the focal point in proportion to and altitude drop (On the fly).

The other method is to just do the standard top down view and hug the ground rather than fly through the air (while leaving the camera stationary to avoid hopping).

Again, you're going to need to monitor your altitude so that you don't go disappearing into mountains or flying Thelma and Louise style off cliffs. I've never tried to do this, but you might look at the IPointOnTerrainGE Interface to start with. Look at the ProjectedOntoGlobe function, as it seems to be the most promising.

http://earth.google.com/comapi/inter...TerrainGE.html
Attached Images
File Type: jpg GE Example.jpg (29.5 KB, 150 views)
__________________
http://www.joshuagayou.com
Reply With Quote
  #8  
Old 04-08-2008, 02:26 AM
xtremedeniz xtremedeniz is offline
Newcomer
 
Join Date: Apr 2008
Posts: 2
Default GE addsymbols

Thanks for your quick reply. I really disappointed but i have another question.
Is it possible to add points(placemarks) with a specified symbol. It is ok for me if i can add symbols by changing color and size.
Reply With Quote
  #9  
Old 04-08-2008, 08:24 AM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

Sure it is. If you look at the CGEAircraft class, go to the UpdateKmlFile method. The code that barfs out the kml to file (all the print statements) has one section that reads as follows:

Code:
Print #FileNum, "        <Icon>"
    Print #FileNum, "          <href>root://icons/palette-2.png</href>"
    Print #FileNum, "          <w>32</w>"
    Print #FileNum, "          <h>32</h>"
    Print #FileNum, "        </Icon>"
This specifies the icon to use for the marker on the map.

See the following site:
http://code.google.com/apis/kml/docu...s_21.html#icon
__________________
http://www.joshuagayou.com
Reply With Quote
  #10  
Old 04-30-2008, 03:31 AM
imarshad imarshad is offline
Newcomer
 
Join Date: Dec 2003
Posts: 11
Default Vb.net

Thanks gayouj,
Your code works perfectly in VB6... However like swdev I need to develop almost a similar application in VB.NET 2008.... I tried the upgradation wizard of Visual Studio 2008 and most of the code is automatically converted to VB.NET... However the first stumbling block I am facing is with the API calls of SetTimer..

m_TimerID = SetTimer(m_hWnd, ObjPtr(Me), m_Interval, AddressOf TimerProc)

I get the following Warnings
'UPGRADE_WARNING: Add a delegate for AddressOf TimerProc
'UPGRADE_ISSUE: ObjPtr function is not supported.

I am confident about the first warning as I can add a delegate but I dont know how to replace ObjPtr in VB.NET?
Also VB.NET is suggesting me to use System.Threading.Timer instead of SetTimer and KillTimer.... So it will be very nice if you can help me in figuring out how to use the SetTimer in vb.net and also how you have overcome the problem in VB.NET....
Reply With Quote
  #11  
Old 04-30-2008, 09:28 AM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

Just get rid of the CTimer class and use the System.Timers.Timer class. The VB6 CTimer class in my project is more or less the same functionality. The .NET version is superior, though, because you don't need to send it a window handle.

Since there has been so much demand for the .NET code, I'll see if I can get it isolated from my master assembly and post it today.
__________________
http://www.joshuagayou.com
Reply With Quote
  #12  
Old 04-30-2008, 12:13 PM
gayouj's Avatar
gayouj gayouj is offline
Junior Contributor

* Expert *
 
Join Date: Jan 2006
Location: California
Posts: 317
Default

I have uploaded the .NET code for this functionality at the following link:

http://www.xtremevbtalk.com/showthre...11#post1285211
__________________
http://www.joshuagayou.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->