Click here to Skip to main content
15,867,834 members
Articles / Web Development / HTML

Google Earth in your Windows Form

Rate me:
Please Sign up or sign in to vote.
3.57/5 (6 votes)
19 Aug 2009CPOL2 min read 95.8K   5.4K   50   17
Use Google Earth`s complete functionality on your Windows Form
GoogleEarth.png

Introduction

Almost everyone who is reading this article would have used Google Earth. So here I show how you can use it in your Windows application. It provides all the navigation functionalities of Google Earth. 

Requirements 

The basic requirements which should be fulfilled to use this utility are:

  • Google Earth Plug-in should be installed on your system (small one, takes a minute or two). When you will run this application, it will show you the link itself, so you don't need to worry about it.
  • Since this uses Google APIs, you should have an App key from Google (it's quite easy to get one). Get it from here.
  • You should have Visual Studio installed on your system.

Basic Fundamental

We have an HTML page (using JavaScript) which just displays Google Earth on it. So the basic idea is that we will add a browser control to our application and set the URL to our HTML page. 

HTML Page 

The HTML page uses JavaScript and is not made up of a thousand lines of code. All the work is done by Google. We just need to call certain functions so that we could have the work done.

HTML
<html>
<head>
   <title>Sample</title>
   <script src="http://www.google.com/jsapi?key="My App key here"> </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> 

Please notice the first script tag. In its key attribute, you need to add your App key which you get from Google. Even I have one, but I don't feel like making it public. 

Creating Windows Form 

  1. Create a Windows Forms application 
  2. To your form, add a browser control as shown below:  

AddBrowser.png

In the forms designer file (Form1.Designer.cs), change the URL property of your browser control to the HTML file. Also change the URI kind to absolute. 

C#
this.webBrowser1.Url = new System.Uri(System.Environment.CurrentDirectory + "\\" +
       "MYFiles\\MyGoogleEarthFile.html", System.UriKind.Absolute);

Set the height of your browser control to 400 and width to 600 because these are the dimensions in which our Google earth will be shown. 

FINAL STEP

The final step isn't some big piece of code. So just run your application. That's it.

Do post your comments on the article, whatever way you feel about it. Thanks !!!! 

History

  • 19th August, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
I'm a ruby developer in LinkedIn these days but used to code in C# some years back for my hobby projects.

Comments and Discussions

 
QuestionDoes not show anything :S Pin
Member 1102206727-Aug-14 8:32
Member 1102206727-Aug-14 8:32 
QuestionGoogle Earth in Windows Form Pin
TobyTwerl25-Jun-14 18:14
TobyTwerl25-Jun-14 18:14 
GeneralMy vote of 1 Pin
fraser_chapman30-Nov-13 15:45
fraser_chapman30-Nov-13 15:45 
GeneralMy vote of 1 Pin
fraser_chapman30-Nov-13 15:40
fraser_chapman30-Nov-13 15:40 
Questiongo to location Pin
ms_vb10-Jul-12 18:48
ms_vb10-Jul-12 18:48 
GeneralVery good for GE Plugin beginners Pin
Dave1975199529-Jul-11 5:05
Dave1975199529-Jul-11 5:05 
Questionwhy can form not resize? Pin
xiaohan18-Nov-09 4:22
xiaohan18-Nov-09 4:22 
AnswerRe: why can form not resize? Pin
HiteshSharma24-Nov-09 22:56
HiteshSharma24-Nov-09 22:56 
GeneralNice Work Pin
Mohit.naughty28-Aug-09 8:02
Mohit.naughty28-Aug-09 8:02 
Rantplagiarism sucks... Pin
fraser_chapman27-Aug-09 23:28
fraser_chapman27-Aug-09 23:28 
GeneralRe: plagiarism sucks... Pin
Dave1975199529-Jul-11 4:36
Dave1975199529-Jul-11 4:36 
GeneralRe: plagiarism sucks... Pin
HiteshSharma29-Jul-11 9:33
HiteshSharma29-Jul-11 9:33 
GeneralRe: plagiarism sucks... Pin
fraser_chapman30-Nov-13 15:39
fraser_chapman30-Nov-13 15:39 
QuestionGo to location? Pin
YojoaDon24-Aug-09 8:10
YojoaDon24-Aug-09 8:10 
AnswerRe: Go to location? Pin
HiteshSharma24-Aug-09 21:09
HiteshSharma24-Aug-09 21:09 
yes it is possible .... i have done it and i will ad it here.....
for zoom level this one also has got it just roll your mouse`s central roller over it to zoom and see there that navigation controls are there on the right side.

i`ll add it soon ........ even there is code to show local news on the basis of area being searched.
GeneralAbout the API Pin
xliqz19-Aug-09 7:21
xliqz19-Aug-09 7:21 
GeneralRe: About the API Pin
HiteshSharma19-Aug-09 21:58
HiteshSharma19-Aug-09 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.