Старт
This commit is contained in:
46
observation/pscripts/track.php
Normal file
46
observation/pscripts/track.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
//Выбираю точки запрошенного маршрута и отправляю в виде JSON клиенту
|
||||
|
||||
if(!isset($HTTP_RAW_POST_DATA))
|
||||
{ $HTTP_RAW_POST_DATA = file_get_contents("php://input");
|
||||
}
|
||||
|
||||
$object = json_decode($HTTP_RAW_POST_DATA);
|
||||
|
||||
if($object->date_start=='') $object->date_start='null';
|
||||
if($object->date_end=='') $object->date_end='null';
|
||||
|
||||
require_once("../../monitoring/config.php");
|
||||
|
||||
$db = connectToDB();
|
||||
$db->exec('SET TIME ZONE 0;');
|
||||
|
||||
$sql = 'select id,lon,lat,round(extract(epoch from date at time zone \'utc\')) udate,speed,velocity from main.terminals_locations where del=false and object_id='.$object->object_id.' and ('.$object->date_start.' is null or date > to_timestamp('.$object->date_start.')::timestamp) and ('.$object->date_end.' is null or date < to_timestamp('.$object->date_end.')::timestamp) order by date;';
|
||||
|
||||
try
|
||||
{
|
||||
$res = $db->query($sql);
|
||||
}catch (Exception $e)
|
||||
{ echo $e->getMessage();
|
||||
$res = null;
|
||||
}
|
||||
|
||||
//Массив объектов
|
||||
$json ='[';
|
||||
while ($row = $res->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
$json .="\n";
|
||||
$json .='{';
|
||||
$json .='"lat":"'.$row['lat']."\",\n";
|
||||
$json .='"lon":"'.$row['lon']."\",\n";
|
||||
$json .='"udate":"'.$row['udate']."\",\n";
|
||||
$json .='"speed":"'.round ($row['speed'], 1)."\",\n";
|
||||
$json .='"velocity":"'.round ($row['velocity'], 1)."\"\n";
|
||||
$json .='},';
|
||||
}
|
||||
if($json!='[')
|
||||
$json = substr($json,0,strlen($json)-1);
|
||||
$json .=']';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo $json;
|
||||
Reference in New Issue
Block a user