latitude = 0;
$average->longitude = 0;
$average->inTime = 0;
$encoded_average = '';
$count_loc = count($file);
for ($i = 0; $i < $count_loc; $i++)
{
$decoded_location = json_decode($file[$i]);
$array_inTime = array_map('intval',explode(':',$decoded_location->inTime));
$array_sum_of_time[0] = $array_sum_of_time[0] + $array_inTime[0];
$array_sum_of_time[1] = $array_sum_of_time[1] + $array_inTime[1];
$array_sum_of_time[2] = $array_sum_of_time[2] + $array_inTime[2];
$sum_of_lat = $sum_of_lat + $decoded_location->latitude;
$sum_of_long = $sum_of_long + $decoded_location->longitude;
if ($i+1 == $count_loc)
{
$average->latitude = $sum_of_lat/$count_loc;
$average->longitude = $sum_of_long/$count_loc;
$average->inTime = strval(floor($array_sum_of_time[0]/$count_loc)) . ":" . strval(floor($array_sum_of_time[1]/$count_loc)) . ":" . strval(floor($array_sum_of_time[2]/$count_loc));
$encoded_average = json_encode($average);
}
}
//echo $average->latitude. "
". $average->longitude. "
". $average->inTime . "
". $encoded_average;
header('Content-Type: application/json');
echo $encoded_average;