
这是我找到的最好方法。当然,这需要您在数据库中对所有经纬度的邮政编码进行编码。
// 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),并将您的列表用户带回来。
编码愉快!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)