Skip to content

Instantly share code, notes, and snippets.

@adamelso
Created April 6, 2014 22:27
Show Gist options
  • Save adamelso/10012134 to your computer and use it in GitHub Desktop.
Save adamelso/10012134 to your computer and use it in GitHub Desktop.
<?php
namespace ArchFizz\Gpx;
use Doctrine\Common\Collections\ArrayCollection;
class Coordinate
{
private $latitude;
private $longitude;
public function __construct($latitude, $longitude)
{
$this->latitude = $latitude;
$this->longitude = $longitude;
}
}
class Path
{
private $coordinates;
public function __construct()
{
$this->coordinates = new ArrayCollection();
}
public function addCoordinate(Coordinate $coordinate)
{
$this->coordinates->add($coordinate);
}
}
class Gpx
{
private $path;
public function __construct(Path $path)
{
$this->path = $path;
}
public function import($pathToGpxFile)
{
$gpx = simplexml_load_file($pathToGpxFile);
$data = $gpx->gpx->trk;
$name = $data->name;
foreach ($data->trkseg as $trackPoint) {
$this->path->addCoordinate(
new Coordinate($trackPoint->attributes()->lat, $trackPoint->attributes()->lon)
);
}
return $this->path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment