相关疑难解决方法(0)

MySQL大圆距离(Haversine公式)

我有一个工作的PHP脚本,它获取经度和纬度值,然后将它们输入到MySQL查询中.我想把它做成MySQL.这是我目前的PHP代码:

if ($distance != "Any" && $customer_zip != "") { //get the great circle distance

    //get the origin zip code info
    $zip_sql = "SELECT * FROM zip_code WHERE zip_code = '$customer_zip'";
    $result = mysql_query($zip_sql);
    $row = mysql_fetch_array($result);
    $origin_lat = $row['lat'];
    $origin_lon = $row['lon'];

    //get the range
    $lat_range = $distance/69.172;
    $lon_range = abs($distance/(cos($details[0]) * 69.172));
    $min_lat = number_format($origin_lat - $lat_range, "4", ".", "");
    $max_lat = number_format($origin_lat + $lat_range, "4", ".", "");
    $min_lon = number_format($origin_lon - $lon_range, "4", ".", "");
    $max_lon = …
Run Code Online (Sandbox Code Playgroud)

php mysql great-circle

181
推荐指数
4
解决办法
10万
查看次数

寻找'X'公里(或英里)内的城市

这可能会也可能不会很清楚,如果我不在基础上,或者您需要更多信息,请给我留言.也许有一个解决方案已经在我想要的PHP中.

我正在寻找一个函数,它将增加或减去经度OR纬度值的距离.

原因:我有一个包含所有纬度和经度的数据库,并希望形成一个查询来提取X公里(或英里)内的所有城市.我的查询看起来像这样......

Select * From Cities Where (Longitude > X1 and Longitude < X2) And (Latitude > Y1 and Latitude < Y2)

 Where X1 = Longitude - (distance)
 Where X2 = Longitude + (distance)

 Where Y1 = Latitude - (distance)
 Where Y2 = Latitude + (distance)
Run Code Online (Sandbox Code Playgroud)

我在PHP中工作,使用MySql数据库.

也欢迎任何建议!:)

mysql gis distance coordinates coordinate-systems

12
推荐指数
1
解决办法
1万
查看次数