Oct 06 2008

C# GPS Tracking en Windows Mobile (4 parte)

Category: ProgramacionIndigo @ 3:06 PM

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.

¡Compartelo!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • BarraPunto
  • Bitacoras.com
  • LinkedIn
  • Meneame
  • RSS
  • Technorati
  • Twitter

Tags: , , , , ,

3 Responses to “C# GPS Tracking en Windows Mobile (4 parte)”

  1. www.programame.net says:

    C# GPS Tracking en Windows Mobile (4 parte)…

    Aquí está la cuarta de entrega de GPS Tracking en Windows Mobile. En está ocasión generaremos un fichero de posiciones gps siguiente el estandar gpx….

  2. Rober says:

    Hola. Estoy intentando hacer una aplicación para que desde mi pda (wm6) me diga la velocidad media que estoy realizando… me gustaria poder recibir ayuda de cualquier tipo. . . .
    Un saludo y enhorabuena por el blog :)

  3. Indigo says:

    Hola Rober, la verdad es que no me he puesto a calcular velocidades con información GPS, por lo que no puedo decir mucho. Aunque imagino que en google habrá información de la fórmulas a utilizar.