sql查询附近的人的实例
TABLE_NAME 表结构,分别是自增ID,城市ID,经纬度
id city_id y x
1 1901 22.982087 113.318505
2 1901 23.079377 113.298556
LAT/LNG分别是纬度经度,由客户端传过来的
select city_id,y,x,ACOS(SIN((LAT * 3.1415) / 180) * SIN((y * 3.1415) / 180 ) + COS((LAT* 3.1415) / 180 ) * COS((y * 3.1415) / 180 ) *COS((LNG* 3.1415) / 180 - (x * 3.1415) / 180 ) ) * 6380 as distance from TABLE_NAME WHERE city_id=1901 ORDER BY distance
mysql示例
select city_id,y,x,ACOS(SIN((23.13678584271096 * 3.1415) / 180) * SIN((y * 3.1415) / 180 ) + COS((23.13678584271096 * 3.1415) / 180 ) * COS((y * 3.1415) / 180 ) *COS((113.2937260476958* 3.1415) / 180 - (x * 3.1415) / 180 ) ) * 6380 as distance fromTABLE_NAME WHERE city_id=1901 ORDER BY distance
相关推荐:
以上就是sql查询附近的人的实例的详细内容,更多请关注其它相关文章!
上一篇: DoitPHP 1.4正式版已公布