diff --git a/classes/Geo.php b/classes/Geo.php
index 7967b98..6ef7d9a 100644
--- a/classes/Geo.php
+++ b/classes/Geo.php
@@ -16,7 +16,16 @@ class Geo
$delta_lat = ($lat2 - $lat1);
$delta_lng = ($lng2 - $lng1);
- return (6378137 * acos(cos($lat1) * cos($lat2) * cos($lng1 - $lng2) + sin($lat1) * sin($lat2)));
+ $distance = (6378137 * acos(cos($lat1) * cos($lat2) * cos($lng1 - $lng2) + sin($lat1) * sin($lat2)));
+
+ if (isset($latlng1['alt']) && isset($latlng2['alt']) && $latlng1['alt'] <> $latlng2['alt']) {
+// var_dump($distance, abs($latlng1['alt'] - $latlng2['alt']));
+ $altDelta = abs($latlng1['alt'] - $latlng2['alt']);
+ $distance = sqrt(pow($distance, 2) + pow($altDelta, 2));
+// var_dump($distance);die;
+ }
+
+ return $distance;
}
static function formatedDistance($distance)
diff --git a/controllers/JsonController.php b/controllers/JsonController.php
index 69dc53c..a1354b1 100644
--- a/controllers/JsonController.php
+++ b/controllers/JsonController.php
@@ -625,7 +625,7 @@ class JsonController extends Controller
if ($tracks) {
foreach ($tracks as $track) {
$resLatlngs = array();
- $trackPoints = TrackPoints::model()->getAll(array('where' => '`trackId` = ?'), array($track->id));
+ $trackPoints = TrackPoints::model()->getAll(array('where' => '`trackId` = ?', 'order'=>'id'), array($track->id));
if ($trackPoints) {
foreach ($trackPoints as $trackPoint) {
$resLatlngs[] = array(
diff --git a/controllers/TracksController.php b/controllers/TracksController.php
index 63bafd6..1bdbec4 100644
--- a/controllers/TracksController.php
+++ b/controllers/TracksController.php
@@ -108,6 +108,22 @@ class TracksController extends Controller
));
}
+ function actionExport()
+ {
+ $id = intval(App::getParam('id'));
+ $trip = Trips::model()->getByPK($id);
+
+ if ($trip->isEmpty() || $trip->owner != App::$user->id) {
+ App::error404();
+ }
+
+ self::renderPartial('/tracks/gpx.php', array(
+ 'trip' => $trip,
+ 'waypoints' => WayPoints::model()->getAll(array('where' => '`tripId` = ?'), array($trip->id)),
+ 'tracks' => Tracks::model()->getAll(array('where' => '`tripId` = ?'), array($trip->id)),
+ ));
+ }
+
function actionImport()
{
$id = (int) App::getParam('id');
@@ -206,25 +222,29 @@ class TracksController extends Controller
foreach ($trkpt as $tpt) {
$speed = isset($tpt->extensions->geotrackerMeta['s']) ? floatval($tpt->extensions->geotrackerMeta['s']) : 0;
+ $alt = isset($tpt->ele) ? floatval($tpt->ele) : 0;
$trackPoint = TrackPoints::model()->add(
array(
'trackId' => $track->id,
'lat' => floatval($tpt['lat']),
'lng' => floatval($tpt['lon']),
- 'alt' => isset($tpt->ele) ? floatval($tpt->ele) : 0,
+ 'alt' => $alt,
'createdAt' => isset($tpt->time) ? $tpt->time : date('c'),
'speed' => $speed,
)
);
if ($prevPoint) {
- $distanceTmp += Geo::distance($prevPoint, array('lat' => floatval($tpt['lat']), 'lng' => floatval($tpt['lon'])));
+ $distanceTmp += Geo::distance($prevPoint, array('lat' => floatval($tpt['lat']), 'lng' => floatval($tpt['lon']), 'alt' => $alt));
}
$prevPoint = array(
'lat' => floatval($tpt['lat']),
'lng' => floatval($tpt['lon']),
);
+ if (isset($tpt->ele)) {
+ $prevPoint['alt'] = floatval($tpt->ele);
+ }
$tptCount++;
}
diff --git a/views/tracks/gpx.php b/views/tracks/gpx.php
new file mode 100644
index 0000000..955be1f
--- /dev/null
+++ b/views/tracks/gpx.php
@@ -0,0 +1,51 @@
+
+
+
+ = $trip->name ?>
+ = $trip->description ?>
+
+
+
+ = App::$user->nick ?>
+
+
+
+
+
+
+ = $wpt->alt ?>
+
+ = $wpt->name ?>
+ = $wpt->description ?>
+
+
+
+
+
+ = $trip->name ?>
+
+
+ = $trip->distance ?>
+ = $trip->createdAt ?>
+
+
+
+getAll(array('where' => '`trackId` = ?', 'order'=>'id'), array($track->id)); ?>
+
+
+
+ = $tpt->alt ?>
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/views/tracks/index.php b/views/tracks/index.php
index 56194c4..8f3b3ea 100644
--- a/views/tracks/index.php
+++ b/views/tracks/index.php
@@ -25,6 +25,9 @@ if ($trips) {
+
+
+
= $trip->id ?> —
= $trip->name ?> (= $trip->createdAt ?>)
status == Trips::STATUS_PUBLIC):?>