C#调用GoogleEarth COM API开发(一)

一、准备 Google Earth提供了个人免费版、Plus版、Pro版,个人开发只安装个人免费版就可以了,如果需要更多的功能,那么只有每年上交$400购买专业版了 到目前为止,GoogleEarth的二次开发接口还比较少,功能太弱,仅仅提供了1.0的类库。 GoogleEarth COM API参考文档可以在这里找到:http://earth.google.com/comapi/index.html C#调用COM的参考资料多如牛毛,大家可以到网上搜一下 二、例子 这里提供一个利用VS2008 + Google Earth 5.0开发一个“Hello world”程序 首先,确保已经正确安装GE,打开VS2008 ,新建一个Windows应用程序项目,在“项目”菜单中选择“添加引用…”,切换到“COM”选项卡,选择“Google Earth 1.0 Type Library”,其实就是Google Earth的主程序 在项目的引用中你可以看到已经添加了一个EARTHLib的引用,然后我们就可以调用其中的接口进行开发了。 下面就是小例子的代码(功能很简单,只有三个,打开GE,然后让GE保存一张截图,然后可以打开这个截图看看。呵呵) 复制 保存 // 功能:GE实例 // 描述:GE COM API 网址:http://earth.google.com/comapi/index.html // 作者:温伟鹏 // 日期:2008-01-20 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using EARTHLib; using System.Runtime.InteropServices; using System.IO; using System.Diagnostics; namespace GEDemo { public partial class Form1 : Form { /// <summary> /// 标记GE是否已经启动 /// </summary> private bool isGeStarted = false; /// <summary> /// 定义GE应用程序类 /// </summary> private ApplicationGEClass GeApp; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { StartGE(); } /// <summary> /// 启动GE /// </summary> private void StartGE() { if (isGeStarted) { return; } try { GeApp = (ApplicationGEClass) Marshal.GetActiveObject("GoogleEarth.Application"); isGeStarted = true; } catch { GeApp = new ApplicationGEClass(); isGeStarted = true; } } private void button2_Click(object sender, EventArgs e) { string ssFile = Path.Combine(Application.StartupPath, "ScreenShot.jpg"); try { //quality的取值范围在(0,100)之间,质量越高,quality越大 GeApp.SaveScreenShot(ssFile, 100); MessageBox.Show("成功保存截屏图像:" + ssFile); } catch (Exception ex) { MessageBox.Show("保存截屏图像时发生错误:" + ex.Message); } } private void button3_Click(object sender, EventArgs e) { string ssFile = Path.Combine(Application.StartupPath, "ScreenShot.jpg"); if (!File.Exists(ssFile)) { MessageBox.Show("未能找到保存的截屏图像!"); return; } Process.Start(ssFile); } private void button4_Click(object sender, EventArgs e) { this.Close(); Application.Exit(); } } }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值