GPS坐标Mysql查询

时间:2016-01-20 16:17:52

标签: php mysql gps

假设我有$longitude=2; $latitude =3; 我想从数据库中获取信息

Select * 
from info 
where longitude is between $longitude + 2 AND $longitude-2  
AND latitude is between $latitude + 2 AND $latitude -2

如何编写此查询以获取特定区域的信息

1 个答案:

答案 0 :(得分:0)

$longitude = 2;
$latitude = 3;

$longitude_min = $longitude - 2;
$longitude_max = $longitude + 2;
$latitude_min = $latitude - 2;
$latitude_max = $latitude +2;

$sql = "SELECT * FROM `info`
WHERE `longitude`>$longitude_min
AND `longitude`<$longitude_max
AND `latitude`>$latitude_min
AND `latitude`<$latitude_max";

$result = mysql_query($sql);