Click here to Skip to main content
Licence CPOL
First Posted 19 Aug 2009
Views 27,642
Downloads 1,220
Bookmarked 43 times

Google Earth in your Windows Form

By | 19 Aug 2009 | Article
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>
<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. 

 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)

About the Author

HiteshSharma



India India

Member

I am a siebel developer by profession and a C#, ASP.Net, Javascript, C, C++ developer by Hobby. I code mostly for fun and usually code to create utilities and applications to enhance, improve and ease out my work while working on my computer. I try to make my computer a better place to code. I work on electronics as well and like to create hardware which may integrate with my computer. Now a days i code mostly for web and spend more and more of my time on javascript.
 
visit my blog at: http://msphitesh.blogspot.in

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralVery good for GE Plugin beginners PinmemberDave197519955:05 29 Jul '11  
Questionwhy can form not resize? Pinmemberxiaohan4:22 18 Nov '09  
AnswerRe: why can form not resize? PinmemberHiteshSharma22:56 24 Nov '09  
GeneralNice Work PinmemberMohit.naughty8:02 28 Aug '09  
Rantplagiarism sucks... Pinmemberfraser_chapman23:28 27 Aug '09  
GeneralRe: plagiarism sucks... PinmemberDave197519954:36 29 Jul '11  
GeneralRe: plagiarism sucks... PinmemberHiteshSharma9:33 29 Jul '11  
QuestionGo to location? PinmemberYojoaDon8:10 24 Aug '09  
AnswerRe: Go to location? PinmemberHiteshSharma21:09 24 Aug '09  
GeneralAbout the API Pinmemberxliqz7:21 19 Aug '09  
GeneralRe: About the API PinmemberHiteshSharma21:58 19 Aug '09  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 19 Aug 2009
Article Copyright 2009 by HiteshSharma
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid