GPX parsing patterns and “standards”

后端 未结 2 1394
渐次进展
渐次进展 2020-12-17 05:53

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

2条回答
  •  时光说笑
    2020-12-17 06:38

    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.

提交回复
热议问题