2016-01-25 59 views
0

如何約默認計算約60英里使用經緯度和緯度如何計算默認約默認約60英里yii

在yii。

$criteria->with = array('merchant'); 
    $criteria->select = '*, (3959 * acos(cos(radians(' . $latitude . ')) 
      * cos(radians(merchant.lat)) * cos(radians(merchant.lng) - 
      radians(' . $longitude . ')) + sin(radians(' . $latitude . ')) 
      * sin(radians( merchant.lat)))) * 1.609344 AS distance'; 
    $criteria->having=("distance < 4");  

它無法正常工作。

+0

請添加代碼 – AnkiiG

+0

的可能的複製(http://stackoverflow.com/questions/5838481/c-calculating -the-距離之間-2-GPS-位置) – Bonatti

回答

0

MSQL語句將查找距離37,-122座標25英里半徑內最近的20個位置。

SELECT id, (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat)))) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20; 

參考文獻:[?C,計算兩個GPS位置之間的距離] https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=en