0

我正在尝试在 Google 地球中创建轨道(使用 KML)

我正在为 C# 使用SharpKML

我可以成功创建路径。

如何创建轨道?我知道我需要添加一个“点”和一个“时间”,我这样做是通过以下操作 -

            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 轨道添加时间和坐标的正确方法是什么?

4

1 回答 1

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);
于 2015-11-02T12:44:18.577 回答