GPX files that you capture from your GPS device using GPSBabel are in XML and start with the following tags:
<gpx
version="1.0"
creator="GPSBabel - http://www.gpsbabel.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0http://www.topografix.com/GPX/1/0/gpx.xsd"
>
...
You wont be able to read these GPX files from Flex (2.01) without modifying the namespace definition. Here is the problem that you will run into: when you try to get all of the trkpt elements, using a construct such as gpx..trkpt (or any other method of traversing the XML, e.g., gpx.descendants("trkpt")) the ActionScript program will silently fail. The only to way to get around this is to remove the XML name space declaration
xmlns="http://www.topografix.com/GPX/1/0"
from the start of your XML file. This must be a bug in ActionScript. The same GPX file works fine when you read it from DHTML using Google AJAX mapping API.
November 20, 2007 at 6:40 am |
[...] You’ll need to edit the GPX namespace specification before you try to use the [...]
January 27, 2008 at 10:38 pm |
I ran into this same problem… Did you ever find a fix? It seems a shame to have to modify a GPX file to process it…
Thanks!
- Jes
January 28, 2008 at 4:26 am |
I’ve not really looked for a proper fix, I’m afraid. If you do find on, please do let me know.
January 28, 2008 at 5:35 pm |
Defining the namespace in ActionScript program, may help, but I’ve not tried it.
April 4, 2008 at 2:29 am |
Defining the namespace does work, here’s an example….
namespace topo = “http://www.topografix.com/GPX/1/0″;
use namespace topo;
for each (var trkpt:XML in gpx..trkpt) {
April 4, 2008 at 7:12 am |
Perfect. Thank you for the update.
December 16, 2008 at 9:17 pm |
I had the same Problem too. I use the XML-Object as dataprovider in a datagrid. After including the namespace (topo), like in da’s example it seams to work. But it is not possible to read elements inside the -elements like or . Only the attributes @lon + @lat inside the are readable. When I remove the namespace declaration xmlns=”http://www.topografix.com/GPX/1/0″ all sub elements are accessible.
February 4, 2009 at 7:13 pm |
I’m having trouble getting flex to read the gpx even with the new namespace. I’m using HTTPService to read the gpx in e4x resultFormat. I still get “a term is undefined and has no properties” back. Here is the basic code…
XML.ignoreWhitespace = true;
namespace topo = “http://www.topografix.com/GPX/1/0″;
use namespace topo;
var gpx:XML = XML(e.result);
outputTextArea.text += gpx.wpt[0].name + “\n”;
outputTextArea.text += gpx.children(); works great with the new namespace. Removing the namespace from the gpx makes the code above work great. Any help would be great. Thanks.
February 4, 2009 at 10:37 pm |
Hi Brian, I’ve touched that code for a year now so not sure if there is an effective workaround or not. Clearly removing the namespace works, so that may be your best bet.
February 5, 2009 at 5:41 pm |
Hey SJ, thanks for your reply. I figured after almost a year I wouldn’t get anything!
The new namespace actually hasn’t worked for me. The only thing that has worked is removing the topografix namespace from the gpx file (what end users want to do that?) or just treating the xml as a string (NOT elegant).
I’ve been looking into this in my spare time for 3 days now and this is the only place that directly addresses this issue. Do you know if this is an issue with flex or with the namespace?
February 5, 2009 at 5:49 pm |
Here’s a sample of parsing the gpx in Flex with the MapQuest ActionScript API – http://devblog.mapquest.com/2009/02/04/dump-your-garmin/
February 5, 2009 at 7:35 pm |
Hi Brian, I like the source code browser that you’re using. Is it an open source project or did you write it yourself? The MapQuest mash up looks very good. I didn’t know that they were still around.
February 9, 2009 at 7:05 pm |
The source code viewer is part of the Export Release Build in FB3.
Check out the MapQuest Developer Network – definitely still around.
http://developer.mapquest.com/home