1

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?

OneGuyInDc
  • 1,557
  • 2
  • 19
  • 50

1 Answers1

1

You should add the track to a placemark, try something like this:

var root = new Document();
var track = new SharpKml.Dom.GX.Track();

foreach (var gc in myCoords)
{
    var vector = new Vector(gc.Latitude, gc.Longitude);
    track.AddCoordinate(vector);
    track.AddWhen(gc.gpsDateTime);
}

Placemark trackPm = new Placemark();
trackPm.Geometry = track;
root.AddFeature(trackPm);

KmlFile kml = KmlFile.Create(root, false);
Tico Fortes
  • 499
  • 4
  • 6