我试图复制这个问题的答案,但在CakePHP 3中:Search distance between 2 points CakePHP
如何为CakePHP 3动态创建虚拟字段?
这是我的自定义查找程序,由于虚拟字段创建错误,这当然无法正常工作:
protected function findByDistance($lat, $long, $distance)
{
$distanceValue = $this->calcDistance($lat, $long, $this->_properties['latitude'], $this->_properties['longitude']);
$this->virtualFields['distance'] = $distanceValue;
return $query->where(['distance <=' => $distance]);
}