php 6位邮政编码,php / mysql邮政编码邻近搜索

 2023-09-08 阅读 18 评论 0

摘要:这是我找到的最好的方法.当然,这将需要您的所有邮政编码在数据库中编码.// get all the zipcodes within the specified radius - default 20function zipcodeRadius($lat, $lon, $radius){$radius = $radius ? $radius : 20;$sql = 'SELECT distinct(ZipCode) FR

这是我找到的最好的方法.当然,这将需要您的所有邮政编码在数据库中编码.

// get all the zipcodes within the specified radius - default 20

function zipcodeRadius($lat, $lon, $radius)

{

$radius = $radius ? $radius : 20;

$sql = 'SELECT distinct(ZipCode) FROM zipcode 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

$zipcodeList = array();

while($row = $this->db->fetch_array($result))

{

array_push($zipcodeList, $row['ZipCode']);

}

return $zipcodeList;

}

你应该能够放弃这个功能.传递您想要的半径的邮政编码$lat和$lon,包括可选的半径,并获得一个zipcodes列表.

你可以很容易地修改这个,让所有的用户都可以使用zipcode IN(radius_sql),并让你的列表用户回来.

快乐编码!

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/19706.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息