How To Embed GoogleEarth in your Delphi Application (part 1 of 5)
An article by David Hawk, Landenberg, Pennsylvania, USA.
This article describes an easy way to embed GoogleEarth in a Delphi application. Before proceeding too far, you should study Google's Terms of Service. Just because GoogleEarth can be freely downloaded doesn't mean there aren't any restrictions on what you can do with it.
You should be aware that there are actually two APIs for
GoogleEarth. The first, a relatively rudimentary COM API, was
released in Beta form in 2006. The
earth.idl COM interface
GoogleEarth.exe to be scripted by an external
application. This API is still supported and has some documentation.
A heroic programming effort by Luca Rocchi (Rome, Italy) produced
GEPanel for Delphi, a TPanel descendant, which Luca
has made freely available (see the source tab on his website). GEPanel starts the
GoogleEarth.exe process and
employs various Windows tricks to capture GoogleEarth's render
window within the GEPanel client area in order to allow it to be
displayed as part of a Delphi application. The COM interface allows control
of GoogleEarth, and the TPanel ancestor allows the
mouse-down event to be captured for calculating coordinates. This approach
was used in the author's first attempt at incorporating GoogleEarth
into a Delphi application and was fairly successful, however there are some
GoogleEarth.exe only allows a single
instance to run on a given machine. Also the GEPanel code seems
to depend on some implementation details of
which aren't part of Google's specifications, and future changes by Google
could conceivably break it. Luca Rocchi has also released a browser plug-in
for GoogleEarth on his website that has received good reviews, but
it has not been evaluated by this author.
Google has recently released its own GoogleEarth Plug-in which is much easier to use but has a completely different API. This plug-in is extensively documentated on Google's website. The GoogleEarth Plug-in allows multiple instances to run on a machine and allows more control over the application. The plug-in is supplied in various versions to support different browsers, and the Internet Explorer version is an ActiveX control.
A brief unsuccessful attempt to use the ActiveX control directly from Delphi was made, but was abandoned after researching other people's attempts to do this. Their efforts had foundered on poorly documented and changing ActiveX interfaces for the Plug-in that made it apparent that this approach was going against the grain of how Google's engineers intended for it to be used.
A Delphi GoogleEarth demo program was developed for this article. On start-up, after the initialization streaming has completed, the program displays the familiar GoogleEarth globe.
The user enters an address, for example the, and clicks the Geocode Address button. Clicking this button causes the address to be sent to Google to be "geocoded", whereby Google returns a fairly close longitude and latitude for that address. The GoogleEarth plug-in is then directed to zoom in to approximately 200 meters above these approximate coordinates. If the desired house is not in view (usually it is), the user can slide the terrain around until the house appears. The user then clicks on the house itself and precise longitude and latitude are displayed.
This article is copyright © David Hawk 2009-2015
Licensed under a Creative Commons License.