I would like to continue the discussion from this post: GPX Schema validation problems. To go directly to the point, I want to ask how people are parsing and working with GP
i have just worked out a simple gpx parser that i use to scrape tracks and waypoints from a gpx file and save in a database. i have stripped all DB code and left a barebones example.
children() AS $child ) {
$name = $child->getName();
if ($name == 'wpt') {
print_r($name.' ');
echo $child['lat'].' '.$child['lon'].' ';
$name = $child->children()->getName();
if ($name = 'ele') {
echo $child->children().'
';
}
}
if ($name == 'trk') {
foreach( $child->children() AS $grandchild ) {
$grandname = $grandchild->getName();
if ($grandname == 'name') {
echo $grandchild.'
';
}
if ($grandname == 'trkseg') {
foreach( $grandchild->children() AS $greatgrandchild ) {
$greatgrandname = $greatgrandchild->getName();
print_r($greatgrandname.' ');
//echo '
';
if ($greatgrandname == 'trkpt') {
echo $greatgrandchild['lat'].' '.$greatgrandchild['lon'];
foreach( $greatgrandchild->children() AS $elegreatgrandchild ) {
echo $elegreatgrandchild.'
';
}
}
if ($greatgrandname == 'ele') {
print_r($greatgrandchild);
}
}
}
}
}
}
} else {
exit('Failed to open 5alqs2.gpx.');
}
?>
you could take this one step further and parse kml from this. check this link out for more on this subject. Creating a kml file from a mysql database with php
THIS CODE WORKS WITH MULTIPLE TRACKS.