This project has moved. For the latest updates, please go here.

Issues in generated KML file

Apr 14, 2014 at 9:32 AM
I used SharpKML with asp.net(C#) it generates kml which loads and works in Google Maps but problem is that i can't add few things like:
  1. Styles
  2. Start and End points (big yellow pins)
  3. Dividing line string into chunks instead of continuous long line.
i tried everything but it doesn't work even document tag is not added in output.

CODE:
protected void Button1_Click(object sender, EventArgs e)
    {
        var document = new Document();
        document.Id = "Document";
        document.Name = "Document";
        SharpKml.Dom.Style style = new SharpKml.Dom.Style();
        style.Id = "yellowLineGreenPoly";
        //style.Line = new LineStyle(new Color32(HexStringToColor("7f00ffff"),4));

        //Color32 col = HexStringToColor("7f00ffff");
        //LineStyle ls = new LineStyle();
        //ls.Color = col;
        //style.Line = ls;
        //document.AddStyle(style);
        Description ds = new Description();
        ds.Text = @"<h1>Car's Tracking</h1> ";
       

        LineString linestring = new LineString();
        CoordinateCollection coordinates = new CoordinateCollection();
      
        SqlConnection sqlcon = new SqlConnection(conStr);
        SqlCommand sqlcom = new SqlCommand("GetLatLon", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.Parameters.Add("@IMEI", SqlDbType.VarChar).Value= TextBox1.Text;

        DataTable dt = new DataTable();
        SqlDataAdapter sda = new SqlDataAdapter(sqlcom);
        sda.Fill(dt);

        try
        {
            sqlcon.Open();
            sqlcom.ExecuteNonQuery();

            foreach (DataRow dr in dt.Rows) 
            {
                double lon = double.Parse(dr["Longitude"].ToString());
                double lat = double.Parse(dr["Latitude"].ToString());
                coordinates.Add(new Vector(lat, lon));
            }

            linestring.Coordinates = coordinates;
            Placemark placemark = new Placemark();
            placemark.Name = "Car's Track Record";
            placemark.Description = ds;            
           // placemark.StyleUrl = new Uri("#yellowLineGreenPoly", UriKind.Relative);
            placemark.Geometry = linestring;

            document.AddFeature(placemark);
           // linestring.Extrude = true;
            linestring.Tessellate = true;
            linestring.AltitudeMode = AltitudeMode.RelativeToGround;
            var kml = new Kml();
           // kml.Feature = document;
            kml.Feature = placemark;
            KmlFile kmlFile = KmlFile.Create(kml, true);
            using (var stream = System.IO.File.OpenWrite("C:/"+"IMEI-"+TextBox1.Text+".kmz"))
            {
                kmlFile.Save(stream);
                Response.Write("KML Created");
            }

        }
        catch (Exception exc)
        {
            Response.Write(exc.Message);
        }
        finally 
        {
            sqlcon.Close();
        }
    }
Coordinator
Apr 14, 2014 at 12:31 PM
I think you're problem might be here:
var kml = new Kml();
// kml.Feature = document;
kml.Feature = placemark;
It doesn't appear that you're setting the Feature property of kml to the document you've created.
Apr 14, 2014 at 5:58 PM
var kml = new Kml();
// kml.Feature = document;
kml.Feature = placemark;
sir i tried it too but it didn't work.```