首页 > 技术文档 > 技术文档 > lbs应用:mysql查询距离大小sql语句

lbs应用:mysql查询距离大小sql语句

时间:2016-3-4 已查看2305次

It’s also possible to use MySQL to do a calculation to find all records within a specific distance. In this example, I’m going to query MyTable to find all the records that are less than or equal to variable $distance (in Miles) to my location at $latitude and $longitude:

  1. $qry = "SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515) as distance  

  2.  FROM `MyTable`  

  3.  WHERE distance >= ".$distance."  

 

For Kilometers:

  1. $qry = "SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance  

  2. FROM `MyTable`  

  3. WHERE distance >= ".$distance."  


上一篇:lbs应用:php求2点距离 下一篇:百度地图的标注、提示、划线的操作