We run CakePHP v3.x with the Postgres database. I need to select some records whose latitude and longitude are at distance X from another point. PostGIS has a function that does just that , but it seems that I have to fix the original SQL queries in order to use it.
I am not asking for help in writing a raw query, but I'm looking for confirmation as to whether the raw query approach is the right way to use this extension, making the best use of the structure. I searched and found no libraries for the CakePHP ORM extension to enable this. Perhaps there is a third option that I did not think about.
[NOTE: This does not work ...]
public function fetch()
{
$maxMetersAway = 10 * 1000;
$lat = $this->request->query['lat'];
$lng = $this->request->query['lng'];
$stops = $this->Stops->find('all')
->where("ST_DWithin( POINT($lng,$lat), POINT(Stops.lng,Stops.lat), $maxMetersAway")
->toArray();
$this->set(['stops'=>$stops, '_serialize' => true]);
}