gpxParser

The XML Google Maps gpxParser class.

Defined (1)

The class is defined in the following location(s).

/xmlgooglemaps_gpxParser.php  
  1. class gpxParser{ 
  2. var $output = array(); 
  3.  
  4. function parse($path) { 
  5. $this->output = ""; 
  6. if (!($fp = fopen($path, "r"))) { 
  7. die("Cannot open XML data file: $path"); 
  8. return false; 
  9. $filecontent = ""; 
  10. while ($data = fread($fp, 4096)) { 
  11. $filecontent .= $data; 
  12.  
  13. $xml = myFunctions::xml2array($filecontent); 
  14.  
  15. //Bounds 
  16. $this->output["bounds"] = $xml["gpx"]["metadata"]["bounds"]["attr"]; 
  17. //Waypoints 
  18. if (isset($xml["gpx"]["wpt"]["attr"])) { 
  19. $waypts[0] = $xml["gpx"]["wpt"]; 
  20. } else { 
  21. $waypts = $xml["gpx"]["wpt"]; 
  22. for ($i=0; $i<count($waypts); $i++) { 
  23. foreach($waypts[$i] AS $tagname => $element) { 
  24. switch (strtolower($tagname)) { 
  25. case "attr": 
  26. $this->output["wpt".$i] = $element; 
  27. break; 
  28. case "link": 
  29. $this->output["wpt".$i]["link"] = $element["attr"]["href"]; 
  30. break;  
  31. default: 
  32. $this->output["wpt".$i][$tagname] = $element["value"]; 
  33. break;  
  34. $this->output["wpt_count"] = count($waypts); 
  35. //Routes 
  36. if (isset($xml["gpx"]["rte"]["rtept"])) { 
  37. $rtes[0] = $xml["gpx"]["rte"]; 
  38. } else { 
  39. $rtes = $xml["gpx"]["rte"]; 
  40. for ($i=0; $i<count($rtes); $i++) { 
  41. if (isset($rtes[$i]["rtept"]["attr"])) { 
  42. $rtepts[0] = $rtes[$i]["rtept"]; 
  43. } else { 
  44. $rtepts = $rtes[$i]["rtept"]; 
  45. for ($ii=0; $ii<count($rtepts); $ii++) { 
  46. foreach($rtepts[$ii] AS $tagname => $element) { 
  47. switch (strtolower($tagname)) { 
  48. case "attr": 
  49. $this->output["rte".$i]["rtept".$ii] = $element; 
  50. break; 
  51. case "link": 
  52. $this->output["rte".$i]["rtept".$ii]["link"] = $element["attr"]["href"]; 
  53. break;  
  54. default: 
  55. $this->output["rte".$i]["rtept".$ii][$tagname] = $element["value"]; 
  56. break;  
  57. }  
  58. $this->output["rte".$i]["rtept_count"] = count($rtepts); 
  59. $this->output["rte_count"] = count($rtes); 
  60. //Tracks 
  61. $trkcount = 0; 
  62. if (isset($xml["gpx"]["trk"]["trkseg"])) { 
  63. $trks[0] = $xml["gpx"]["trk"]; 
  64. } else { 
  65. $trks = $xml["gpx"]["trk"]; 
  66. for ($i=0; $i<count($trks); $i++) { 
  67. if (isset($trks[$i]["trkseg"]["trkpt"])) { 
  68. $trksegs[0] = $trks[$i]["trkseg"]; 
  69. } else { 
  70. $trksegs = $trks[$i]["trkseg"]; 
  71. for ($ii=0; $ii<count($trksegs); $ii++) { 
  72. if (isset($trksegs[$ii]["trkpt"]["attr"])) { 
  73. $trkpts[0] = $trksegs[$ii]["trkpt"]; 
  74. } else { 
  75. $trkpts = $trksegs[$ii]["trkpt"]; 
  76. for ($iiii=0; $iiii<count($trkpts); $iiii++) { 
  77. foreach($trkpts[$iiii] AS $tagname => $element) { 
  78. switch (strtolower($tagname)) { 
  79. case "attr": 
  80. $this->output["trk".$trkcount]["trkpt".$iiii] = $element; 
  81. break; 
  82. case "link": 
  83. $this->output["trk".$trkcount]["trkpt".$iiii]["link"] = $element["attr"]["href"]; 
  84. break;  
  85. default: 
  86. $this->output["trk".$trkcount]["trkpt".$iiii][$tagname] = $element["value"]; 
  87. break;  
  88. }  
  89. $this->output["trk".$trkcount]["trkpt_count"] = count($trkpts); 
  90. $trkcount++; 
  91. $this->output["trk_count"] = $trkcount; 
  92.  
  93.  
  94.