mysql 通過經緯度查詢附近的地點位置(谷歌方案)


 1 SELECT    
 2   id, `name`,(    
 3     6371 * acos (    
 4       cos ( radians(60.000000) )    
 5       * cos( radians( lat ) )    
 6       * cos( radians( lon ) - radians(70.000000) )    
 7       + sin ( radians(60.000000) )    
 8       * sin( radians( lat ) )    
 9     )    
10   ) AS distance    
11 FROM t_demo  
12 HAVING distance < 2    
13 ORDER BY distance   
14 LIMIT 0 , 20;    

說明:當前位置緯度:60.000000 經度:70.000000  以公里代替里程搜索,用6371替換3959。

英文原文:

The SQL statement that will find the closest 20 locations that are within a radius of 30 miles to the 78.3232, 65.3234 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 30 miles, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM