73 lines
2.3 KiB
PHP
Executable File
73 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
$timestamp = intval(microtime(true)*1000);
|
|
$lat = 51.0543666;
|
|
$lng = 13.7445584;
|
|
$acc = 80;
|
|
$ele = 152;
|
|
|
|
echo json_encode(Array('timestamp'=>$timestamp, 'coords'=>Array('latitude'=>$lat, 'longitude'=>$lng, 'accuracy'=>$acc, 'altitude'=>$ele)));
|
|
|
|
exit();
|
|
|
|
// TODO: calc % between two positions and
|
|
|
|
$file = $_GET['file'];
|
|
|
|
$valid_name = preg_match('#[a-z0-9_ \.]+#i',$file);
|
|
$exists = is_file('routes/'.$file.'.gpx');
|
|
// var_dump(!$valid_name, !$exists); echo '<br/>';
|
|
|
|
if(!$valid_name || !$exists) $file = preg_replace('#^(routes\/){0,1}([a-z0-9_ \.\/]+?)\.gpx$#i', '$2', glob('routes/*.gpx')[0]);
|
|
|
|
//echo $file.'<br />';
|
|
|
|
$gpx = simplexml_load_file('routes/'.$file.'.gpx');
|
|
$start = strtotime($gpx->xpath('/gpx/trk/trkseg/trkpt/time')[0]);
|
|
$end = strtotime(end($gpx->xpath('/gpx/trk/trkseg/trkpt/time')));
|
|
|
|
$pos = (time()-strtotime("00:00")) % ($end-$start); // seconds since midnight % total seconds of track --> position on track
|
|
|
|
$last = 0;
|
|
$c=0;
|
|
foreach($gpx->xpath('/gpx/trk/trkseg/trkpt') as $trkpt)
|
|
{
|
|
$time = strtotime($trkpt->xpath('time')[0]);
|
|
if($last - $start < $pos || $pos == 0) { // find last passed point
|
|
$last = $time;
|
|
$c++;
|
|
continue;
|
|
}
|
|
else // last position found --> calc position between points
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
// $akt_time = (time()-strtotime("00:00"));
|
|
echo intval(($last-$start) / 3600).':'.(intval(($last-$start) / 60) % 60).':'.(($last-$start) % 60)."\n"; // time since route start
|
|
echo intval($pos / 3600).':'.(intval($pos/60)%60).':'.($pos % 60)."\n"; // time since route start
|
|
$pos = ($last-$start) / ($pos-$last);
|
|
|
|
echo $c.' '.$trkpt->attributes()['lat'].' '.$trkpt->attributes()['lon'].' '.($pos*100)."\n";
|
|
var_dump($gpx->xpath('/gpx/trk/trkseg/trkpt')[$c]); echo "\n";
|
|
|
|
|
|
/*
|
|
foreach($gpx->xpath('/gpx/trk/trkseg/trkpt') as $trkpt)
|
|
{
|
|
if (($timestamp = strtotime($trkpt->xpath('time'))) === false) {
|
|
echo "Die Zeichenkette ($str) ist nicht parsebar.";
|
|
} else {
|
|
echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
|
|
}
|
|
}
|
|
*/
|
|
|
|
$timestamp = intval(microtime(true)*1000);
|
|
$lat = 51.0543666;
|
|
$lng = 13.7445584;
|
|
$acc = 80;
|
|
$ele = 152;
|
|
|
|
echo json_encode(Array('timestamp'=>$timestamp, 'position'=>Array('latitude'=>$lat, 'longitude'=>$lng, 'accuracy'=>$acc, 'elevation'=>$ele))); |