Mysql 查找接近距离GPS
我有一个mysql表,其中包含GPS坐标纬度和经度 我想请求在指定位置附近获取记录 我尝试了2个请求并合并了结果,但结果不正确Mysql 查找接近距离GPS,mysql,gps,request,location,coordinates,Mysql,Gps,Request,Location,Coordinates,我有一个mysql表,其中包含GPS坐标纬度和经度 我想请求在指定位置附近获取记录 我尝试了2个请求并合并了结果,但结果不正确 //Req 1 - bigger than my position $req1 = mysql_query('SELECT * FROM table WHERE latitude >= 47.6621549 and longitude >= 2.3547128 ORDER BY latitude, longitude'); //Req 2 - saml
//Req 1 - bigger than my position
$req1 = mysql_query('SELECT * FROM table WHERE latitude >= 47.6621549 and longitude >= 2.3547128 ORDER BY latitude, longitude');
//Req 2 - samller than my position
$req2 = mysql_query('SELECT * FROM table WHERE latitude <= 47.6621549 and longitude <= 2.3547128 ORDER BY latitude, longitude');
一个请求就可以完成吗?
有了这个,我想用gmap距离API检索到给定位置的距离,我认为这不是问题
谢谢你的回答。试试这个
$range = 2;/* 2 mi */
mysql_query("SELECT t1.*,
(
3956 * 2 *
ASIN(
SQRT(
POWER(SIN(($lat - t1.latitude) * pi()/180 / 2), 2)
+ COS($lat * pi()/180) * COS(t1.latitude * pi()/180)
* POWER(SIN(($lng - t1.longitude) * pi()/180 / 2), 2)
)
)
) AS distance
FROM table
HAVING distance < $range
ORDER BY distance ASC");
这个答案可能会对你有所帮助:这很可能与你的问题有关,非常感谢!!我把换算英里数的乘法加进去KM@jlafforgue如果需要公里数,请将3956更换为6371