将坐标集合datatable 存为googleearth可打开的kml文件
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.Filter = "Google地图轨迹(*.kml)|所有文件(*.*)";
saveFile.ShowDialog();
if (saveFile.FileName.Trim() == "") return;
string filename = saveFile.FileName + ".kml";
// Create the file and writer.
FileStream fs = new FileStream(filename, 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(filename);
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/aws0.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(filename);
w.WriteEndElement();
//write styleurl
w.WriteStartElement("styleUrl");
w.WriteString("#exampleStyleMap");
w.WriteEndElement();
// Write Point element
w.WriteStartElement("LineString");
w.WriteStartElement("coordinates");
string points = "";
for (int i = 0; i < _dtHistoryPoints.Rows.Count; i++)
{
string lng = _dtHistoryPoints.Rows[i]["Longitude"].ToString();
string lat = _dtHistoryPoints.Rows[i]["Latitude"].ToString();
points += lng + "," + lat + ",0 ";
}
w.WriteString(points);
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement(); // Placemark
w.WriteEndElement();//document
w.WriteEndElement(); // kml
// Ends the document.
w.WriteEndDocument();
// close writer
w.Close();