日期:2014-05-18  浏览次数:21063 次

有人用c#写过kml文件吗,和写xml一样吗,给个建议,谢了!
creatkml

------解决方案--------------------
C# code
  // Create the file and writer.
            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/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("zy's KML");
            w.WriteEndElement();
            //write styleurl
            w.WriteStartElement("styleUrl");
            w.WriteString("#exampleStyleMap");
            w.WriteEndElement();


            // Write Point element
            w.WriteStartElement("Point");
            w.WriteStartElement("coordinates");
            w.WriteString("-122.0856545755255,37.42243077405461,0");
            w.WriteEndElement();
            w.WriteEndElement();

            w.WriteEndElement(); // Placemark
            w.WriteEndElement();//document
            w.WriteEndElement(); // kml

            // Ends the document.
            w.WriteEndDocument();

            // close writer
            w.Close();