We have a database with workshops and their coordinates. Once the data is passed to an array, we measure the distance from the location point entered on a map (or by geolocation) and the nearest workshops.
I do a foreach to collect the coordinates of each workshop, as shown in the image, and I need to collect in another array only the workshops whose distance is lower, to then pass them through JSON.
The problem is that when doing:
if (distancia_a $distancia) {
array_push($data, $resultado);
}
Only the first workshop picks me up and ignores the rest.
Could you help me out?
$coorYLocat=$coords['lat'];
$coorXLocat=$coords['lng'];
$RadYLocat=($coorYLocat*pi())/180;
$RadXLocat=($coorXLocat*pi())/180;
}
$stmt->execute();
// $stmt->debugDumpParams();
$data=$stmt->fetchAll(PDO::FETCH_ASSOC);
$RADIOTIERRA = '6371';
$i=0;
foreach ($data as $taller => $resultado);
{
$coorYTaller=$resultado['coordinate_y'];
$coorXTaller=$resultado['coordinate_x'];
$RadYTaller=($coorYTaller*pi())/180;
$RadXTaller=($coorXTaller*pi())/180;
$distance_a = acos(sin($RadYLocat)*sin($RadYTaller) + cos($RadYLocat) * cos($RadYTaller) * cos ($RadXLocat-$RadXTaller)) * $RADIOTIERRA;
if ($distance_a <= $distance)
{
array_push($datos, $resultado);
}
}
echo json_encode($datos);