In a CakePHP (v3) application, how can I retrieve the closest results based on passed lat lng values?
I\'d like to have them back as native CakePHP entities, so some
finally i got the solution for this. below is the working example
$distance = 25;
$start_latitude = 12.920479;
$start_longitude = 77.670547;
$contents = $this->Sightings->find()->select(['latitude', 'longitude', 'distance' => 'SQRT(
POW(69.1 * (latitude - '.$start_latitude.'), 2) +
POW(69.1 * ('.$start_longitude.' - longitude) * COS(latitude / 57.3), 2))'])->having(["distance < " => $distance]);
output
{"lat": xx.920479,
"lng": xx.670547,
"distance": "0"
}