First, create a new project and add a timer control and button. When you click the button, the content in dynamic. kml is dynamically updated, so that the coordinates of the point are changed in real time. The Code is as follows:
private double xx=100;private double yy=30;private void timer1_Tick(object sender, EventArgs e){ xx +=0.03; yy +=0.03; FileStream fs = new FileStream("products.kml", FileMode.Create); XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8); // Start the document. w.WriteStartDocument(); w.WriteStartElement("kml", "http://earth.google.com/kml/2.1"); w.WriteStartElement("Document"); w.WriteStartElement("name"); w.WriteString("zy's KML"); w.WriteEndElement(); w.WriteStartElement("open"); w.WriteString("1"); w.WriteEndElement(); //style w.WriteStartElement("Style"); w.WriteAttributeString("id", "normalPlacemark"); w.WriteStartElement("IconStyle"); w.WriteStartElement("Icon"); w.WriteStartElement("href"); w.WriteString("F:/img/web.gif"); w.WriteEndElement();//style w.WriteEndElement();//iconStyle w.WriteEndElement();//icon w.WriteEndElement();//href //stylemap w.WriteStartElement("StyleMap"); w.WriteAttributeString("id", "exampleStyleMap"); w.WriteStartElement("Pair"); w.WriteStartElement("key"); w.WriteString("normal"); w.WriteEndElement(); w.WriteStartElement("styleUrl"); w.WriteString("#normalPlacemark"); w.WriteEndElement();//styleUrl w.WriteEndElement();//pair w.WriteEndElement();//StyleMap w.WriteStartElement("Placemark"); w.WriteStartElement("Name"); w.WriteString("zy's KML"); w.WriteEndElement(); // Write Point element w.WriteStartElement("Point"); w.WriteStartElement("coordinates"); w.WriteString(xx.ToString ()+","+yy.ToString ()); w.WriteEndElement(); w.WriteEndElement(); w.WriteEndElement(); // Placemark w.WriteEndElement();//document w.WriteEndElement(); // kml // Ends the document. w.WriteEndDocument(); // close writer w.Close(); }
Create the realtimenetlink. kml file and call the dynamic. kml content again each time the kml is refreshed. The Code is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>RealtimeNetlink </name>
<visibility>1</visibility>
<open>1</open>
<NetworkLink>
<visibility>1</visibility>
<refreshVisibility>1</refreshVisibility>
<flyToView>0</flyToView>
<LookAt>
<longitude>114.12022</longitude>
<latitude>22.55841667</latitude>
<altitude>2000</altitude>
<range>1000</range>
<tilt>0</tilt>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<Link>
<refreshMode>onInterval</refreshMode>
<refreshInterval>3</refreshInterval>
<viewRefreshMode>onStart</viewRefreshMode>
<viewRefreshTime>3</viewRefreshTime>
</Link>
</NetworkLink>
</Document>
</kml>