none
Google Earth in C# (Noob Ahead)

    Question

  • Hi,

    I'm trying to make google earth appear in my little program but I'm not sure how to do that. This is the code I got from someone else but I don't know how to continue.

    Code Snippet

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using EARTHLib;
    using System.Threading;


    namespace GoogleEarth
    {
        public partial class GoogleEarthViewPort : UserControl
        {
            public delegate int EnumWindowsProc(IntPtr hwnd, int lParam);


            [DllImport("user32", CharSet = CharSet.Auto)]
            public extern static IntPtr GetParent(IntPtr hWnd);


            [DllImport("user32", CharSet = CharSet.Auto)]
            public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);


            [DllImport("user32", CharSet = CharSet.Auto)]
            public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


            public GoogleEarthViewPort()
            {
                InitializeComponent();
            }


            private IntPtr GEHrender = (IntPtr)0;
            private IntPtr GEParentHrender = (IntPtr)0;


            public ApplicationGEClass googleEarth;


            private void GoogleEarthViewPort_Load(object sender, EventArgs e)
            {
                if (this.DesignMode == false)
                {
                    googleEarth = new ApplicationGEClass();


                    GEHrender = (IntPtr)googleEarth.GetRenderHwnd();
                    GEParentHrender = GetParent(GEHrender);


                    MoveWindow(GEHrender, 0, 0, this.Width, this.Height,true);
                    SetParent(GEHrender, this.Handle);
                }
            }


            public void Unload()
            {
                if (GEParentHrender != (IntPtr)0)
                    SetParent(GEHrender, GEParentHrender);
            }


            private void GoogleEarthViewPort_Resize(object sender,EventArgs e)
            {
                if (GEHrender != (IntPtr)0)
                    MoveWindow(GEHrender, 0, 0, this.Width, this.Height,true);
            }
        }

     

    }

     

     

     

    I already added the reference EARTHLib in Google Earth.

    Can someone help me please? Thank you.

    Friday, July 27, 2007 6:58 AM

Answers


  • Here is a reference to Google Earth API documentation. I see it's not like MSDN, but some research must help you.

    linkCake
    Friday, July 27, 2007 10:19 AM

All replies


  • Here is a reference to Google Earth API documentation. I see it's not like MSDN, but some research must help you.

    linkCake
    Friday, July 27, 2007 10:19 AM
  • This is a WinFX User control. So what you want to do is to create a Windows 'User Control', and then add them into your Win Form.

    Monday, June 09, 2008 6:47 PM
  • Hi,

    You will have much more luck using the supported plug-in api rather than the un-supported COM api.

    Take a look at this small example I blogged some time ago.
    http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html

    Also, I have been working on a library of controls and helper classes to work with the plug-in from managed code.
    You can see the project here.
    http://code.google.com/p/winforms-geplugin-control-library/

    The basis of the control library interaction is the COM Google Earth Plugin Type Library (plugin_ax.dll) converted into the equivalent definitions in a common language runtime assembly. This is great as the Api for the plugin lets you work with a whole host of features and objects that are not exposed via the EARTH COM api.

    Anyhow, I hope that is some use to you.

    Regards,

    Fraser.
    Yea right...
    Friday, March 06, 2009 12:16 AM
  • From source, right click the reference item that has EARTHLib and click properties, Set interop to FALSE. Done

     

    • Proposed as answer by guayaco10040 Wednesday, January 04, 2012 7:39 PM
    Wednesday, January 04, 2012 7:38 PM
  • I suspect that after more than 3 years the problem is solved, or the OP has given up. :)
    Regards David R
    ---------------------------------------------------------------
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.
    Wednesday, January 04, 2012 8:14 PM