Google Earth Long Lat


This C# application demonstrates how to create a simple Google Earth Longitude and Latitude value point application, that create Google Earth KML file on user desktop and then open it in Google Application. This project is my First Semester Software Engineering Project and its open source  :). Application Requirements:

  • Google Earth
  • Visual Studio 2010 or 2012
  • Little Knowledge about C# 🙂

Software Overview:

Google Earth Longitude and Latitude

Source Code:

Form1.Designer.cs]

namespace Google
{
partial class Form1
{
/// 
/// Required designer variable.
/// 
private System.ComponentModel.IContainer components = null;

/// 
/// Clean up any resources being used.
/// 
///true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// 
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// 
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.TextBox2 = new System.Windows.Forms.TextBox();
this.TextBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label2
//
this.label2.AutoSize = true;
this.label2.BackColor = System.Drawing.SystemColors.ControlText;
this.label2.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.ForeColor = System.Drawing.Color.AliceBlue;
this.label2.Location = new System.Drawing.Point(193, 250);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(87, 19);
this.label2.TabIndex = 7;
this.label2.Text = "Longitude";
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.SystemColors.ControlText;
this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(193, 223);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 19);
this.label1.TabIndex = 6;
this.label1.Text = "Latitude";
//
// TextBox2
//
this.TextBox2.Location = new System.Drawing.Point(306, 250);
this.TextBox2.Name = "TextBox2";
this.TextBox2.Size = new System.Drawing.Size(156, 20);
this.TextBox2.TabIndex = 5;
this.TextBox2.Text = "67.1150657744";
//
// TextBox1
//
this.TextBox1.Location = new System.Drawing.Point(306, 222);
this.TextBox1.Name = "TextBox1";
this.TextBox1.Size = new System.Drawing.Size(156, 20);
this.TextBox1.TabIndex = 4;
this.TextBox1.Text = "24.9453851704";
//
// button1
//
this.button1.Location = new System.Drawing.Point(287, 302);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 8;
this.button1.Text = "Submit";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.BackColor = System.Drawing.SystemColors.ControlText;
this.label3.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.Color.White;
this.label3.Location = new System.Drawing.Point(491, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(122, 19);
this.label3.TabIndex = 9;
this.label3.Text = "Hammad Khan";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::Google.Properties.Resources.google_earth_splash;
this.ClientSize = new System.Drawing.Size(625, 398);
this.Controls.Add(this.label3);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.TextBox2);
this.Controls.Add(this.TextBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Google Earth Latitude & Longitude";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox TextBox2;
private System.Windows.Forms.TextBox TextBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label3;

}
}

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Diagnostics;

namespace Google
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
String filename = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
filename = filename + @"\latlon.kml";
XmlDocument doc = new XmlDocument();
XmlElement docEle = doc.CreateElement("Placemark");
doc.AppendChild(docEle);

XmlElement root = doc.DocumentElement;

XmlElement infoEle = doc.CreateElement("LookAt");
XmlElement nameEle = doc.CreateElement("latitude");
XmlElement responseEle = doc.CreateElement("longitude");

infoEle.AppendChild(nameEle);
nameEle.InnerText = TextBox1.Text;
infoEle.AppendChild(responseEle);
responseEle.InnerText = TextBox2.Text;

root.AppendChild(infoEle);

doc.Save(filename);

Process.Start(filename);
}
}
}

click-here fot download

Advertisements

13 thoughts on “Google Earth Long Lat

  1. hi, can you please send me the file including in bin and debug folders??
    as i m having problem in implementing the above code.

  2. can u help me i have to creat application that i have to put longitude and latitude and have the picture of the location and put a dot with color in this location please help thnx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s