Create a track for Google Earth

May 12, 2015 at 7:54 PM
I am trying to create a track in Google Earth (Using a KML)

I am using sharpKML for C#

I can successfully create a path.

How do I create a track? I understand that I need to add a "point" and a "when" and I do so by doing the following -
            SharpKml.Dom.GX.Track myTrack = new SharpKml.Dom.GX.Track();
            GpsSensorDataPoint data = (GpsSensorDataPoint)myGPSDataList[i];
            double lat = data.Latitude;
            double lon = data.Longitude;
            double height = data.Height;
            SharpKml.Dom.Point myPoint = new SharpKml.Dom.Point();
            myPoint.Coordinate = new Vector(lat, lon, height);
            myTrack.AddCoordinate(myPoint.Coordinate);
            myTrack.AddWhen(data.CalendarTime.ToLongTimeString());
However the KML created does not have the right syntax
I get the following in the KML which is incorrect:
  <when xmlns="http://www.opengis.net/kml/2.2">12:00:17 AM</when>
  <gx:coord xmlns:gx="http://www.google.com/kml/ext/2.2">-81.3184973901226 29.0765012024324 50.5</gx:coord>
What is the proper way to add a time and coordinate to the SharpKML track?
Coordinator
May 13, 2015 at 5:14 AM
When you say the created KML is incorrect, are you referring to the namespaces? Unfortunately Google Earth doesn't handle them very well, even though the generated KML is perfectly valid XML.

However, there is a workaround for Google Earth compatibility, which is to add the namespace to the root element, which will prevent them appearing in the child elements:
var root= new Kml();
root.AddNamespacePrefix(KmlNamespaces.GX22Prefix, KmlNamespaces.GX22Namespace);
root.Feature = ...
If that's not the issue can you expand on what's the current output and what's the output you're expecting?

Thanks,
Sam