Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 查找接近距离GPS_Mysql_Gps_Request_Location_Coordinates - Fatal编程技术网

Mysql 查找接近距离GPS

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

我有一个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 - 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