PHP Code:
<?php
function inputRouteTrack($routeId, $points) {
if(empty($points) || !is_array($points)) return false;
$query = "INSERT INTO `geo_points` (`id`, `route`, `lat`, `lng`, `alt`, `time`)";
foreach($points as $p) {
$pnts[] = "(NULL, $routeId, '".floatval($p->lat)."', '".floatval($p->lng)."', '".floatval($p->alt)."', '".intval($p->time)."')";
}
$query .= " VALUES ".implode(',',$pnts);
$res = $this->query($query);
return $this->affected;
}
<?
Very well this fix the error and now upload the GPS files however IT IS NOT BROWSING THE TRAIL correctly , now the messages are :
PHP Code:
<?php
class Route {
var $points; //array with points
var $lats; //array with latitudes
var $maxlat;
var $minlat;
var $lngs; //array with longitudes
var $maxlng;
var $minlng;
var $alts; //array with elevations
var $maxalt;
var $minalt;
var $n;
var $dist; //total distance in metres
var $drop; //total drop in metres
var $time; //time the route spent in secconds
var $hours;
var $minutes;
function fromPoints($points) {
$this->n = count($points);
for($i = 0; $i < $this->n; $i++) {
$this->lats[$i] = $points[$i]->lat;
$this->lngs[$i] = $points[$i]->lng;
$this->alts[$i] = $points[$i]->alt;
}
//max and min
$this->maxlat = max($this->lats);
$this->maxlng = max($this->lngs);
$this->maxalt = max($this->alts);
$this->minlat = min($this->lats);
$this->minlng = min($this->lngs);
$this->minalt = min($this->alts);
$this->drop = $this->getDrop($points);
$this->dist = $this->getTotalDistance($this->lats,$this->lngs,$this->alts);
$this->time = $points[($this->n-1)]->time - $points[0]->time;
$this->hours = floor($this->time / 3600);
$this->minutes = floor(($this->time - 3600 * $this->hours) / 60);
}
function getDrop($points) // returns total drop in
{
$n = count($points);
$drop = 0;
for($i = 1; $i < $n; $i++)
{
if($points[$i]->alt > $points[($i-1)]->alt)
$drop += round($points[$i]->alt - $points[($i-1)]->alt);
}
return $drop;
}
function distAB($lat1,$lng1,$alt1,$lat2,$lng2,$alt2) { //returns the distance in metres between two points
$distKM = 6371000 * acos(cos(deg2rad($lat1))*cos(deg2rad($lat2))*cos(deg2rad($lng2)-deg2rad($lng1))+sin(deg2rad($lat1))*sin(deg2rad($lat2)));
$dist = sqrt(pow($distKM,2)+pow(($alt1-$alt2),2));
return $dist;
}
function getTotalDistance($lats,$lngs,$alts) { //returns total distance in meters
$step = 1;
$total = count($lats);
$a = $b = $c = 0;
//this algorithm takes the max and the min difference distances, to calculate a pitagoric distance at the end
for($i = $step; $i < $total; $i += $step) {
$latn = abs($lats[$i]-$lats[$i-$step]);
$lngn = abs($lngs[$i]-$lngs[$i-$step]);
$a += max($latn,$lngn);
$b += min($latn,$lngn);
$c += abs($alts[$i]-$alts[$i-$step]);
}
return $this->distAB(0,0,0,$a,$b,$c);
}
}
?>
It seems me something with the $points also.
Bookmarks