public function mqttStatus($data, $lat, $lnt, $type = 1)
{
$p_status = 0;
$distance = new Distance();
if ($type == 1) {
$p_status = 0;
$i = 0;
$mqtt = [];
foreach ($data['content'][0]['path'] as $value) {
$mqtt[] = [
'lng' => $value[0],
'lat' => $value[1]
];
}
$p_mqtt_status1 = $distance->isInsidePolygon(['lat' => $lat, 'lng' => $lnt], $mqtt);
if ($p_mqtt_status1 == true) {
$p_status = 0;
return $p_status;
} else {
$p_status = 2;
return $p_status;
}
} else if ($type == 2) {
$array_stop = array_column($data['content'], 'path');
$stop_data_er = [];
foreach ($array_stop as $stop) {
$stop_data = [];
$j = 0;
foreach ($stop as $stop_value) {
$stop_data[] = [
'lng' => $stop_value[0],
'lat' => $stop_value[1]
];
}
$stop_data_er[] = $stop_data;
$p_mqtt_status2 = $distance->isInsidePolygon(['lat' => $lat, 'lng' => $lnt], $stop_data);
if ($p_mqtt_status2 == false) {
$p_status = 1;
break;
return $p_status;
}
}
}
return $p_status;
}
public static function isInsidePolygon($point, $polygon)
{
$n = count($polygon);
$inside = false;
for ($i = 0, $j = $n - 1; $i < $n; $j = $i++) {
if (((($polygon[$i]['lat'] <= $point['lat']) && ($point['lat'] < $polygon[$j]['lat'])) ||
(($polygon[$j]['lat'] <= $point['lat']) && ($point['lat'] < $polygon[$i]['lat']))) &&
($point['lng'] < ($polygon[$j]['lng'] - $polygon[$i]['lng']) * ($point['lat'] - $polygon[$i]['lat']) / ($polygon[$j]['lat'] - $polygon[$i]['lat']) + $polygon[$i]['lng'])) {
$inside = !$inside;
}
}
return $inside;
}