Using Google Earth in a Windows Forms Application


Introduction

Google Earth is a map of the world on steroids. You can zoom and glide over stitched together satellite photos of the world. Use Google Earth to find driving directions, find nearby restaurants, measure the distance between two locations, do serious research, or go on virtual vacations.

Download Google Earth from http://earth.google.com/

Platforms:
 

Google Earth 4(beta) is available for Windows 2000/XP, Mac OS 10.3.9 or higher, and Linux

Versions

There are three main versions, free, Plus, and Pro. Google Earth Plus is only available for Windows users and adds GPS support as well as enhanced drawing and sketching. Google Earth Pro 4 beta is available for Mac or Windows. It is designed for commercial users.
Most users won't require more than the free version.

The Google Earth Interface

Google Earth opens with a view of the world from space. Clicking and dragging on the planet will gently spin the globe. The middle scroll wheel or right-click dragging will zoom in and out for close-up views. In some areas the close-ups are detailed enough to make out cars and even people.

If you pass over the upper right-hand corner of the globe, the small compass will turn into the larger navigation control. Click and drag the circle to turn the map. North on the compass will move accordingly. Click on the arrows to move left or right, or use the star in the middle as a joystick to move in any direction. The dial to the right controls zoom levels.

Tilted View

You can tilt the globe to have a perspective view and move the horizon line up or down. This lets you view close-ups as if you were just above them, rather than viewing straight down. It also comes in very handy with the 3-D Buildings. This view is best with the Terrain layer turned on.

Layers

Google Earth can provide a lot of information about a location, and if you were to view it all at once, it would just be confusing. To remedy this, the information is stored in layers, which can be turned on or off. Layers include roads, border labels, parks, food, gas, and lodging.

Terrain and 3D buildings

Two layers are useful for creating a more three dimensional globe. Terrain simulates the elevation levels, so when you tilt your view, you can see mountains and other terrain objects. The 3D Buildings layer lets you zoom through cities, such as San Francisco, and fly between buildings. Buildings are only available for a limited number of cities, and they are only available in gray, unshaded shapes (although there is additional textured building info available for download.)

For more information and to see live videos check this article: http://google.about.com/od/googledesktopsoftware/fr/earthrev.htm

Get Started:

Let's get started.

Create a new Windows Application in Visual Studio 2005 or 2008 or later versions using Windows Forms.

Now drag and drop a Web Browser control from Toolbox to Form.

When you install Google Earth on your machine, you will be running GoogleEarth.exe. Find this exe on your machine where you installed Google Earth and add GoogleEarth.exe to your Windows Forms application's bin folder.

Now add a new HTML page to your Windows Forms application and past the fillowing code to your HTML page.

This script key is provided by Google.

<script src="http://www.google.com/jsapi?key=ABQIAAAAOh61kmAMajizdQht-Zz3MhReSrBDmGipqiQxKIYFIGIHpqaJ1BRq6XLUD-i7BPkx7XreIBQJ1MetxQ"> </script>

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

   <title>Sample</title>

   <script src="http://www.google.com/jsapi?key=ABQIAAAAOh61kmAMajizdQht-Zz3MhReSrBDmGipqiQxKIYFIGIHpqaJ1BRq6XLUD-i7BPkx7XreIBQJ1MetxQ"> </script>

   <script type="text/javascript">

      var ge;

      google.load("earth", "1");

 

      function init() {

         google.earth.createInstance('map3d', initCB, failureCB);

      }

 

      function initCB(instance) {

         ge = instance;

         ge.getWindow().setVisibility(true);

 

ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

 

       ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);

  ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

      }

 

      function failureCB(errorCode) {

      }

 

      google.setOnLoadCallback(init);

   </script>

 

</head>

<body>

   <div id="map3d" style="height: 400px; width: 600px;">

</div>

     

</body>

</html>

Now set the Web Browser control's URL to that .htm page location, which you just added to your application in your code behind. You can write this code on Form's Load event handler. 

this.webBrowser1.Url = new System.Uri(System.Environment.CurrentDirectory + "\\" + "Files\\MyGoogleEarthFile.htm", System.UriKind.Absolute);

Now build and run the application.

You will see output looks like Figure 1. Google Earth is running within your Windows Forms application.

1.jpg

Figure 1

Double click on Web Browser and use your keyboard arrow buttons to find locations.

2.jpg
Figure 2

For more information in details download the attached application.


Up Next
    Ebook Download
    View all
    Learn
    View all