通过客户端传过来的经纬度,保存在数据库,用sql语句查询出附近的人,本文主要和大家分享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
相关推荐:
php实现搜索附近的人功能
php 附近的人
php查询附近的人及其距离的实现方法_php
以上就是sql查询附近的人的实例的详细内容。