C#调用GoogleEarthCOMAPI开发

上传人:lizhe****0001 文档编号:47524828 上传时间:2018-07-02 格式:DOC 页数:31 大小:3.68MB
返回 下载 相关 举报
C#调用GoogleEarthCOMAPI开发_第1页
第1页 / 共31页
C#调用GoogleEarthCOMAPI开发_第2页
第2页 / 共31页
C#调用GoogleEarthCOMAPI开发_第3页
第3页 / 共31页
C#调用GoogleEarthCOMAPI开发_第4页
第4页 / 共31页
C#调用GoogleEarthCOMAPI开发_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《C#调用GoogleEarthCOMAPI开发》由会员分享,可在线阅读,更多相关《C#调用GoogleEarthCOMAPI开发(31页珍藏版)》请在金锄头文库上搜索。

1、C#调用 GoogleEarth COM API 开发一、准备Google Earth 提供了个人免费版、Plus 版、Pro 版,个人开发只安装个人免费版就可以了,如果需要更多的功能,那么只有每年上交$400 购买专业版了到目前为止,GoogleEarth 的二次开发接口还比较少,功能太弱,仅仅提供了 1.0 的类库。GoogleEarth COM API 参考文档可以在这里找到:http:/ COM 的参考资料多如牛毛,大家可以到网上搜一下二、例子这里提供一个利用 VS2008 + Google Earth 5.0 开发一个“Hello world”程序首先,确保已经正确安装 GE,打开

2、VS2008 ,新建一个 Windows 应用程序项目,在“项目”菜单中选择“添加引用”,切换到“COM”选项卡,选择“Google Earth 1.0 Type Library”,其实就是 Google Earth 的主程序在项目的引用中你可以看到已经添加了一个 EARTHLib 的引用,然后我们就可以调用其中的接口进行开发了。下面就是小例子的代码(功能很简单,只有三个,打开 GE,然后让 GE 保存一张截图,然后可以打开这个截图看看。呵呵)1: / 功能:GE 实例2: / 描述:GE COM API 网址:http:/ / 作者:温伟鹏4: / 日期:2008-01-205: 6: us

3、ing System;7: using System.Collections.Generic;8: using System.ComponentModel;9: using System.Data;10: using System.Drawing;11: using System.Text;12: using System.Windows.Forms;13: using EARTHLib;14: using System.Runtime.InteropServices;15: using System.IO;16: using System.Diagnostics;17: 18: namesp

4、ace GEDemo19: 20: public partial class Form1 : Form21: 22: / 23: / 标记 GE 是否已经启动24: / 25: private bool isGeStarted = false;26: / 27: / 定义 GE 应用程序类28: / 29: private ApplicationGEClass GeApp;30: 31: public Form1()32: 33: InitializeComponent();34: 35: 36: private void button1_Click(object sender, EventA

5、rgs e)37: 38: StartGE();39: 40: 41: / 42: / 启动 GE43: / 44: private void StartGE()45: 46: if (isGeStarted)47: 48: return;49: 50: 51: try52: 53: GeApp = (ApplicationGEClass)Marshal.GetActiveObject(“GoogleEarth.Application“);54: 55: isGeStarted = true;56: 57: catch58: 59: GeApp = new ApplicationGEClass

6、();60: 61: isGeStarted = true;62: 63: 64: 65: private void button2_Click(object sender, EventArgs e)66: 67: string ssFile = Path.Combine(Application.StartupPath, “ScreenShot.jpg“);68: 69: try70: 71: /quality 的取值范围在(0,100)之间,质量越高,quality 越大72: GeApp.SaveScreenShot(ssFile, 100);73: 74: MessageBox.Show

7、(“成功保存截屏图像:“ + ssFile);75: 76: catch(Exception ex)77: 78: MessageBox.Show(“保存截屏图像时发生错误:“ + ex.Message);79: 80: 81: 82: private void button3_Click(object sender, EventArgs e)83: 84: string ssFile = Path.Combine(Application.StartupPath, “ScreenShot.jpg“);85: 86: if (!File.Exists(ssFile)87: 88: Message

8、Box.Show(“未能找到保存的截屏图像!“);89: return;90: 91: 92: Process.Start(ssFile);93: 94: 95: private void button4_Click(object sender, EventArgs e)96: 97: this.Close();98: Application.Exit();99: 100: 101: 102: 继C#调用 GoogleEarth Com API 开发(一),我 Neil 又带给大家第二篇文章。这一篇文章在第一篇的基础上,展示如何调用 Windows API 将 GoogleEarth 的界面隐

9、藏掉,并将 GoogleEarth 的地图显示在自定义的窗体上。废话少说,直接上代码。1、主窗口代码:1: / 功能:GE 实例(二)2: / 描述:GE COM API 网址:http:/ / 作者:温伟鹏4: / 日期:2009-02-085: 6: using System;7: using System.Collections.Generic;8: using System.ComponentModel;9: using System.Data;10: using System.Drawing;11: using System.Text;12: using System.Windows

10、.Forms;13: using EARTHLib;14: 15: namespace GEDemo16: 17: public partial class Form2 : Form18: 19: / 20: / 用来关闭 GoogleEarth 的消息定义21: / 22: static readonly Int32 WM_QUIT = 0x0012; 23: 24: private IntPtr GEHWnd = (IntPtr)5;25: private IntPtr GEHrender = (IntPtr)5;26: private IntPtr GEParentHrender = (

11、IntPtr)5;27: / 28: / 定义 GE 应用程序类29: / 30: private ApplicationGEClass GeApp;31: 32: public Form2()33: 34: InitializeComponent();35: 36: 37: protected override void OnLoad(EventArgs e)38: 39: base.OnLoad(e);40: 41: if (!this.DesignMode)42: 43: GeApp = new ApplicationGEClass();44: 45: GEHWnd = (IntPtr)

12、GeApp.GetMainHwnd();46: 47: NativeMethods.SetWindowPos(GEHWnd, NativeMethods.HWND_BOTTOM, 0, 0, 0, 0,48: NativeMethods.SWP_NOSIZE + NativeMethods.SWP_HIDEWINDOW);49: 50: GEHrender = (IntPtr)GeApp.GetRenderHwnd();51: GEParentHrender = (IntPtr)NativeMethods.GetParent(GEHrender);52: 53: NativeMethods.M

13、oveWindow(GEHrender, 0, 0, this.Width, this.Height, true);54: 55: NativeMethods.SetParent(GEHrender, this.Handle);56: 57: 58: 59: protected override void OnClosing(CancelEventArgs e)60: 61: base.OnClosing(e);62: 63: NativeMethods.PostMessage(GeApp.GetMainHwnd(), WM_QUIT, 0, 0);64: 65: 66: 2、NativeMe

14、thods 类定义:1: / 功能:Windows API 调用2: / 描述:大家可以参照 MSDN3: / 作者:温伟鹏4: / 日期:2009-02-085: 6: using System;7: using System.Collections.Generic;8: using System.Text;9: using System.Runtime.InteropServices;10: 11: namespace GEDemo12: 13: public class NativeMethods14: 15: DllImport(“user32.dll“, CharSet = CharSet.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号