php - 选择特定距离内的点

标签 php mysql

我的数据库中有很多交易。我想通过发送参数“lat”“lon”和半径从数据库中选择一些特定的交易。 此查询无法正常工作,出了什么问题..

  require('includes/connection.php');  // defines $dsn, $username, $password      
  $lat = $_GET['lat'];  // latitude of centre of bounding circle in degrees
  $lon = $_GET['lon'];  // longitude of centre of bounding circle in degrees
  $rad = $_GET['rad'];  // radius of bounding circle in kilometers
  $R = 6371;  // earth's radius, km
  // first-cut bounding box (in degrees)
  $maxLat = $lat + rad2deg($rad/$R);
  $minLat = $lat - rad2deg($rad/$R);
  // compensate for degrees longitude getting smaller with increasing latitude
  $maxLon = $lon + rad2deg($rad/$R/cos(deg2rad($lat)));
  $minLon = $lon - rad2deg($rad/$R/cos(deg2rad($lat)));

  // convert origin of filter circle to radians
  $lat = deg2rad($lat);
  $lon = deg2rad($lon);
  $sql = "    Select * From  From deals
      Where lat>$minLat And lat<$maxLat
        And lon>$minLon And lon<$maxLon
    Where acos(sin($lat)*sin(radians(lat)) + cos($lat)*cos(radians(lat))*cos(radians(lon)-$lon))*$R < $rad";
echo "Query =".$sql;  
  $points = mysql_query($sql);

最佳答案

它不起作用,因为您有 2 个“WHERE”语句。您可以将第二个“WHERE”更改为“AND”。

关于php - 选择特定距离内的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713743/

相关文章:

PhpSpreadsheet 返回文件而不是保存它

PHP $_GET 变量检查

mysql - 帮助微博(推特克隆)数据库结构?

mySQL - 在插入之后/期间添加预定义的值?有更好的方法吗?

php - 在外部使用 WooCommerce 网关

php - PHP 中的 MongoDB - 如何将项目插入集合中的数组?

javascript - 选择复选框后变量未更新

php - 为什么页面不会用 MAMP 刷新

php - 我想创建一个表,但它给我错误 1046

php - 如何针对从数据库中获取的每条记录存储多个值并将其传递给其他页面