使用cakephp计算距离

时间:2014-12-24 12:33:01

标签: php sql cakephp

我想根据距离公式对列表进行排序。以下查询工作正常,但不知道如何使用cakephp实现这一点。

"SELECT *, ( 3959 * acos( cos( radians($locality_latitude) ) * cos( radians(locality_latitude) ) * cos( radians( locality_longitude ) - radians($locality_longitude) ) + sin( radians($locality_latitude) ) * sin( radians( locality_latitude ) ) ) ) AS distance FROM officers Officer JOIN localities Locality JOIN cities City ON locality.id = officer.locality_id AND city.id = officer.city_id WHERE officer.city_id =$city_id $des ORDER BY instant distance"

1 个答案:

答案 0 :(得分:0)

使用虚拟字段:

public $virtualFields = array(
    'yourDefinition' => 'your calculation'
);

请参阅Virtual fields