使用sharpKML在Google地球中创建一个曲目

时间:2015-05-12 19:34:15

标签: c# sharpkml

我正在尝试在Google地球中创建一个曲目(使用KML)

我正在使用sharpKML进行C#

我可以成功创建路径。

如何制作曲目?我知道我需要添加一个“点”和“何时”,我这样做是通过以下操作来实现的 -

            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());

但是,创建的KML没有正确的语法 我在KML中得到以下内容:

  <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>

为SharpKML轨道添加时间和坐标的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您应该将曲目添加到地标,尝试以下内容:

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);