Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

Styles, Start and End points (big yellow pins), 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.
C#
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();
        //Color clr = Color.FromArgb(100, 150, 75);
        //clr.ToArgb();

        SqlConnection sqlcon = new SqlConnection(conStr);
       // String com = "select Latitude, Longitude from Coordinates where IMEI=@txtIMEI";
        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();
        }
    }
Posted
Updated 13-Apr-14 23:47pm
v2

1 solution

From your code, it looks like you are expecting a miracle. The only item you add to kml object is the placemark. Well, with the placemark you also add linestring and the Coordinates. Though you add the placemark also to the document, there is no line where the document gets added - directly or indirectly - to kml.
 
Share this answer
 
Comments
Hunain Hafeez 14-Apr-14 13:57pm    
sir i commented out those lines, but after un-commenting it doesn't work. sir please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900