phpmysql邮政编码邻近搜索

phpmysql邮政编码邻近搜索,第1张

php / mysql邮政编码邻近搜索

这是我找到的最好方法。当然,这需要您在数据库中对所有经纬度的邮政编码进行编码。

// get all the zippres within the specified radius - default 20function zippreRadius($lat, $lon, $radius){    $radius = $radius ? $radius : 20;    $sql = 'SELECt distinct(ZipCode) FROM zippre  WHERe (3958*3.1415926*sqrt((Latitude-'.$lat.')*(Latitude-'.$lat.') + cos(Latitude/57.29578)*cos('.$lat.'/57.29578)*(Longitude-'.$lon.')*(Longitude-'.$lon.'))/180) <= '.$radius.';';    $result = $this->db->query($sql);    // get each result    $zippreList = array();    while($row = $this->db->fetch_array($result))    {        array_push($zippreList, $row['ZipCode']);    }    return $zippreList;}

您应该能够使用此功能。将您想要的半径的邮政编码的$ lat和$ lon传递给它,包括可选的半径,并返回一个邮政编码列表。

您可以很容易地对其进行修改,以使所有用户的邮政编码都位于(radius_sql),并将您的列表用户带回来。

编码愉快!



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4918262.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存