火影忍者疾风传初代:C#调用Google Earth COM API开发(一)
来源:百度文库 编辑:中财网 时间:2024/10/05 10:51:18
一、准备
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保存一张截图,然后可以打开这个截图看看。呵呵)
1: // 功能:GE实例
2: // 描述:GE COM API 网址:http://earth.google.com/comapi/index.html
3: // 作者:温伟鹏
4: // 日期:2008-01-20
5:
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.Forms;
13: using EARTHLib;
14: using System.Runtime.InteropServices;
15: using System.IO;
16: using System.Diagnostics;
17:
18: namespace GEDemo
19: {
20: public partial class Form1 : Form
21: {
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, EventArgs e)
37: {
38: StartGE();
39: }
40:
41: ///
42: /// 启动GE
43: ///
44: private void StartGE()
45: {
46: if (isGeStarted)
47: {
48: return;
49: }
50:
51: try
52: {
53: GeApp = (ApplicationGEClass)Marshal.GetActiveObject("GoogleEarth.Application");
54:
55: isGeStarted = true;
56: }
57: catch
58: {
59: GeApp = new ApplicationGEClass();
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: try
70: {
71: //quality的取值范围在(0,100)之间,质量越高,quality越大
72: GeApp.SaveScreenShot(ssFile, 100);
73:
74: MessageBox.Show("成功保存截屏图像:" + 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: MessageBox.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: }作者:温伟鹏 [返回顶部] -上一篇:C#里的一些加密解密标准函数示例 下一篇:C# 调用 Google Earth Com API开发(.. 相关文章:
- .NET互操作技术(COM,API)杂谈
- Mysql autocommit 对 Innodb的性能影响
- ajaxToolkit中AutoCompleteExtender 的触发选择事件
- ajaxToolkit:AutoCompleteExtender 用法详解
- 有关AutoCompleteBox组件的研究[5]——Silverlight学习笔记[40..
- 有关AutoCompleteBox组件的研究[4]——Silverlight学习笔记[39..
- 有关AutoCompleteBox组件的研究[3]——Silverlight学习笔记[38..
- 有关AutoCompleteBox组件的研究[2]——Silverlight学习笔记[37..
- 有关AutoCompleteBox组件的研究[1]——Silverlight学习笔记[36..
- C#利用IE浏览器COM组件在WinForm中显示HTML文件
C#调用传统的com
google earth无法连接hk.google.com
Google Earth
Google Earth...
google earth
google earth
google earth
google earth
google earth
google earth
google earth
google earth
google earth
Google Earth
Google Earth
google earth
GOOGLE EARTH
Google Earth
GOOGLE EARTH ?
google earth
google earth
Google Earth
google earth?
google earth