diff --git a/lib/adapters/GPX.class.php b/lib/adapters/GPX.class.php
index c2cc1d81..90f9ac33 100644
--- a/lib/adapters/GPX.class.php
+++ b/lib/adapters/GPX.class.php
@@ -12,6 +12,8 @@
*/
class GPX extends GeoAdapter
{
+ private $namespace = FALSE;
+ private $nss = ''; // Name-space string. eg 'georss:'
/**
* Read KML string into geometry objects
@@ -31,9 +33,13 @@ public function read($gpx) {
*
* @return string The GPX string representation of the input geometries
*/
- public function write(Geometry $geometry) {
+ public function write(Geometry $geometry, $namespace = FALSE) {
if ($geometry->isEmpty()) return NULL;
- return ''.$this->geometryToGPX($geometry).'';
+ if ($namespace) {
+ $this->namespace = $namespace;
+ $this->nss = $namespace.':';
+ }
+ return '<'.$this->nss.'gpx creator="geoPHP" version="1.0">'.$this->geometryToGPX($geometry).''.$this->nss.'gpx>';
}
public function geomFromText($text) {
@@ -146,17 +152,17 @@ protected function geometryToGPX($geom) {
}
private function pointToGPX($geom) {
- return '';
+ return '<'.$this->nss.'wpt lat="'.$geom->getY().'" lon="'.$geom->getX().'" />';
}
private function linestringToGPX($geom) {
- $gpx = '';
+ $gpx = '<'.$this->nss.'trk><'.$this->nss.'trkseg>';
foreach ($geom->getComponents() as $comp) {
- $gpx .= '';
+ $gpx .= '<'.$this->nss.'trkpt lat="'.$comp->getY().'" lon="'.$comp->getX().'" />';
}
- $gpx .= '';
+ $gpx .= ''.$this->nss.'trkseg>'.$this->nss.'trk>';
return $gpx;
}