Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call GoogleEarth COM API in C #

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "C # how to call GoogleEarth COM API", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "C # how to call GoogleEarth COM API" this article.

First, C # calls GoogleEarth COM API to prepare

Google Earth provides personal free version, Plus version and Pro version. Personal development can only install personal free version. If you need more features, you can only pay $400 a year for professional version.

So far, the secondary development interface of GoogleEarth is still relatively few, the function is too weak, only provides a class library of 1.0.

The GoogleEarth COM API reference documentation can be found here: http://earth.google.com/comapi/index.html

There are so many references for C # calling COM, you can search it on the Internet.

2. An example of C # calling GoogleEarth COM API

Here is a program that uses VS2008 + Google Earth 5.0to develop a "Hello world" program

First, make sure that GE is installed correctly, open VS2008, create a new Windows application project, and select "add reference …" from the Project menu. Switch to the "COM" tab and select "Google Earth 1.0 Type Library", which is actually the main program of Google Earth

You can see that an EARTHLib reference has been added in the project reference, and then we can call the interface in it for development.

Here is the code for the small example (the function is very simple, there are only three, open GE, then let GE save a screenshot, and then you can open this screenshot to see. Hehe)

/ / function: GE instance / / description: GE COM API URL: http://earth.google.com/comapi/index.html 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 {/ Mark whether GE has started / private bool isGeStarted = false; / define the GE application class / private ApplicationGEClass GeApp; public Form1 () {InitializeComponent () } private void button1_Click (object sender, EventArgs e) {StartGE ();} / launch GE / 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"); values of try {/ / quality range from (0100). The higher the quality, the larger the quality (ssFile, 100). MessageBox.Show ("Screenshot image saved successfully:" + ssFile);} catch (Exception ex) {MessageBox.Show ("error occurred while saving screenshot image:" + ex.Message) }} private void button3_Click (object sender, EventArgs e) {string ssFile = Path.Combine (Application.StartupPath, "ScreenShot.jpg"); if (! File.Exists (ssFile)) {MessageBox.Show ("failed to find saved screenshot image!") ; return;} Process.Start (ssFile);} private void button4_Click (object sender, EventArgs e) {this.Close (); Application.Exit () } the above is all the content of the article "how to call GoogleEarth COM API in C #". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report