【发布时间】:2012-12-01 01:51:29
【问题描述】:
我正在使用我在网上找到的以下脚本来获取给定集合坐标之间的所有邮政编码。
使用它时,我担心的是,当某些被抓取的邮政编码大于输入的距离时;相差不大 - 大约 20 公里。
function GetPostalCodes($latitude, $longitude, $range) {
$radius = 3959;
$north = rad2deg(asin(sin(deg2rad($latitude)) * cos($range / $radius) + cos(deg2rad($latitude)) * sin($range / $radius) * cos(deg2rad(0))));
$south = rad2deg(asin(sin(deg2rad($latitude)) * cos($range / $radius) + cos(deg2rad($latitude)) * sin($range / $radius) * cos(deg2rad(180))));
$east = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(90)) * sin($range / $radius) * cos(deg2rad($latitude)), cos($range / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($north))));
$west = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(270)) * sin($range / $radius) * cos(deg2rad($latitude)), cos($range / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($north))));
$return = DBSelectAllArrays("SELECT postal FROM postalcodes WHERE (latitude <= $north AND latitude >= $south AND longitude <= $east AND longitude >= $west)");
krsort($return);
if (empty($return)) return false;
return $return;
}
为了获得更准确的结果,我还缺少什么吗?
【问题讨论】:
-
离他们得到的原点(纬度/经度)越远,准确度会降低吗?
-
不知道,我的查询主要是在20KM范围内。
-
实际上似乎变得更糟,当我搜索 40 公里范围时,我得到 100 公里的结果。
-
我相信我只是想通了。即使它说我在搜索公里,我相信它会以英里为单位。
标签: php mysql postal-code