Aquí está la cuarta de entrega de GPS Tracking en Windows Mobile. En la anterior entrega (la podeis leer en http://www.microcode.es/2008/09/29/c-gps-tracking-en-windows-mobile-3-parte/) vimos como grabar las posición que nos daba el GPS en fichero XML. Leyendo un poco por Internet sobre intercambio de datos sobre posicionamiento GPS, encontré que hay un estandard. Este estandard se llama GPX (GPS Exchange Format) y su página web es http://www.topografix.com/gpx.asp. Viendo las especificaciones he visto que hay una para almacenar puntos y otro para almacenar rutas. Estos estandars los podemos ver en las especificaciones xsd (http://www.topografix.com/gpx/1/1/).
En nuestro código tendriamos que el método SavePosition para grabar la posición como xml o como gpx.
[sourcecode language="csharp"]private void SavePosition(object sender, System.EventArgs args)
{
if (gps.Opened)
{
if (position != null)
{
if ((position.LatitudeValid) && (position.LongitudeValid) && (position.SeaLevelAltitudeValid))
{
if (ConfigManager.Config.Xml)
SavePositionXml(position.LatitudeInDegreesMinutesSeconds, position.LongitudeInDegreesMinutesSeconds, position.SeaLevelAltitude);
if (ConfigManager.Config.GpxRte)
SavePositionGpxRte(position.LatitudeInDegreesMinutesSeconds, position.LongitudeInDegreesMinutesSeconds, position.SeaLevelAltitude);
}
}
}
}[/sourcecode]
La función para generar el fichero gpx es la siguiente
[sourcecode language='csharp']private void SavePositionGpxRte(DegreesMinutesSeconds latitude, DegreesMinutesSeconds longitude, float altitude)
{
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string filename = Path.Combine(path, DateTime.Today.ToString(”yyyyMMdd”) + “.rte.gpx”);
XmlDocument xmlDocument = new XmlDocument();
XmlNode rootNode = null;
if (File.Exists(filename))
{
// Cargamos el fichero xml
xmlDocument.Load(filename);
XmlNode xmlHeader = xmlDocument.DocumentElement;
rootNode = xmlHeader.ChildNodes[0]; //
}
else
{
// Creamos el fichero
XmlNode xmlHeader = xmlDocument.CreateElement(”gpx”);
XmlAttribute version = xmlDocument.CreateAttribute(”version”);
version.Value = “1.0″;
XmlAttribute creator = xmlDocument.CreateAttribute(”creator”);
creator.Value = “GPSLocation”;
XmlAttribute schema = xmlDocument.CreateAttribute(”xsi”, “schemaLocation”, “http://www.w3.org/2001/XMLSchema-instance”);
schema.Value = “http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd”;
xmlHeader.Attributes.Append(version);
xmlHeader.Attributes.Append(creator);
xmlHeader.Attributes.Append(schema);
rootNode = xmlDocument.CreateElement(”rte”);
xmlHeader.AppendChild(rootNode);
xmlDocument.AppendChild(xmlHeader);
}
NumberFormatInfo formatInfo = new NumberFormatInfo();
formatInfo.NumberDecimalSeparator = “.”;
XmlNode node = xmlDocument.CreateElement(”rtept”);
XmlAttribute lat = xmlDocument.CreateAttribute(”lat”);
double value = latitude.ToDecimalDegrees();
lat.Value = value.ToString(formatInfo);
XmlAttribute lon = xmlDocument.CreateAttribute(”lon”);
value = longitude.ToDecimalDegrees();
lon.Value = value.ToString(formatInfo);
node.Attributes.Append(lat);
node.Attributes.Append(lon);
rootNode.AppendChild(node);
xmlDocument.Save(filename);
}[/sourcecode]
Este fichero lo podemos ver con google earth (http://earth.google.com/)
Espero que les sea útil.










