1

我想通过坐标进行搜索,即我想要一个像这样工作的函数:

function getLocationsInCircle($lat, $long, $minDist, $maxDist){
    //return all the places that are at least $minDist 
    //kilometers away and no more than $maxDist kilometers away
}

我有一个“位置”表,其中存储所有位置 ID 及其纬度和经度。

hasrsine 公式对于我想做的事情来说已经足够好了

6371 * ACOS(SIN(RADIANS( $lat )) * SIN(RADIANS( latitude )) + COS(RADIANS( $lat )) * COS(RADIANS( latitude )) * COS(RADIANS( longitude ) - RADIANS( $long )))

我只是看不到如何在 Doctrine 中运行该查询。

4

1 回答 1

3

尝试这个 :

Doctrine_query::create()->select('id')
    ->addSelect("(6371 * ACOS(SIN(RADIANS($latitude)) * SIN(RADIANS(l.latitude)) + COS(RADIANS($latitude)) * COS(RADIANS(l.latitude)) * COS(RADIANS(l.longitude) - RADIANS($longitude)))) as Distance")
    ->from('Location l')
    ->having("Distance > $minDist AND Distance < $maxDist");
于 2010-01-20T15:13:41.797 回答