Click here to Skip to main content
Click here to Skip to main content

Google Earth in your Windows Form

, 19 Aug 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

HiteshSharma

India India
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
Follow on   Google+

Comments and Discussions

 
QuestionDoes not show anything :S [modified] PinmemberMember 1102206727-Aug-14 8:32 
QuestionGoogle Earth in Windows Form PinmemberTobyTwerl25-Jun-14 18:14 
GeneralMy vote of 1 Pinmemberfraser_chapman30-Nov-13 15:45 
GeneralMy vote of 1 Pinmemberfraser_chapman30-Nov-13 15:40 
Questiongo to location Pinmemberms_vb10-Jul-12 18:48 
GeneralVery good for GE Plugin beginners PinmemberDave1975199529-Jul-11 5:05 
Questionwhy can form not resize? Pinmemberxiaohan18-Nov-09 4:22 
AnswerRe: why can form not resize? PinmemberHiteshSharma24-Nov-09 22:56 
GeneralNice Work PinmemberMohit.naughty28-Aug-09 8:02 
Rantplagiarism sucks... Pinmemberfraser_chapman27-Aug-09 23:28 
GeneralRe: plagiarism sucks... PinmemberDave1975199529-Jul-11 4:36 
GeneralRe: plagiarism sucks... PinmemberHiteshSharma29-Jul-11 9:33 
GeneralRe: plagiarism sucks... Pinmemberfraser_chapman30-Nov-13 15:39 
QuestionGo to location? PinmemberYojoaDon24-Aug-09 8:10 
AnswerRe: Go to location? PinmemberHiteshSharma24-Aug-09 21:09 
GeneralAbout the API Pinmemberxliqz19-Aug-09 7:21 
GeneralRe: About the API PinmemberHiteshSharma19-Aug-09 21:58 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 19 Aug 2009
Article Copyright 2009 by HiteshSharma
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid