在特定半径中查找邮政编码 [英] Finding Zip Codes in a Specific Radius

查看:63
本文介绍了在特定半径中查找邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了SaniSoft发行的名为Zip Location的流行的PHP/MySQL脚本,它除了一件事之外还很不错:在某些情况下不会.

I have found this popular PHP/MySQL Script called Zip Location by SaniSoft and it works great besides one thing: It doesn't in some instances.

似乎半径在20英里以下的任何邮政编码都返回与20英里相同的邮政编码.我在整个Google上进行了搜索,但无济于事,我想知道是否有人对此情况有所了解.

It seems that any radius under 20 miles returns the same amount of zip codes as 20 miles. I have searched all over google, but to no avail and I was wondering if someone had some insight on this situation.

我宁愿先解决这个问题,然后再付费购买程序,我还可以利用学习经验.该数据库是邮政编码列表以及每个邮政编码的经度和纬度的列表.该脚本使用一种方法来确定输入的邮政编码附近的距离,并根据其lon/lat返回该半径范围内的邮政编码.

I would rather figure out this problem before having to pay for a program, and I could also use the learning experience. The database is a list of zip codes and longitudes and latitudes of each zip code. The script uses a method that determines the distance around the zip code entered and returns the zip codes in that radius based on their lon/lat.

谢谢!

通过使用脚本提供的distance函数,我发现程序给我的邮政编码与我的邮政编码之间的距离为0英里.

From using the distance function that the script provides I have discovered that the distance between the Zip Codes that the program gives me and my zip code are coming up as 0 miles.

主要更新

从研究中可以看出,该数据库具有重复的经/纬度值.使用Zip Locator时请注意这一点.尽管PHP可以完成工作,但是您将需要找到一个新的邮政编码数据库.我将在以后发布我的发现.

From research it turns out that the database has duplicate lat/lon values. Please be aware of this when using Zip Locator. Although the PHP does its job, you will need to find a new Database of zip codes. I will post my findings at a later date.

推荐答案

第二次尝试!

看到您已编辑的问题说明,我将看看您如何分配邮政编码.

Seeing your edited problem statement, I'd look at how you assign your zip values.

如果您的邮政编码是整数而不是字符串,则可能会引入很多错误.最大的问题是美国邮政编码可以以0开头.

Lots of errors can be introduced if your zip codes are integers instead of strings. The biggest problem is that American zip codes can start with 0.

ziptest.php中的示例不好,因为将zip视为整数.当您尝试用整数描述我自己的邮政编码时:

The examples in ziptest.php aren't good, since the treat zips as integers. When you try to describe my own zip code with an integer:

$zip1 = 02446;

PHP将其解释为八进制值2446.phpZipLocator使用该值作为字符串,而无需任何显式转换.因此,PHP将八进制2446的十进制值作为字符串(1318)给出,它根本不是邮政编码.

Its interpreted by PHP as the octal value 2446. phpZipLocator the uses that value as a string without any explicit conversion. PHP therefore gives it the decimal value of octal 2446 as a string (1318) which is not a zip code at all.

phpZipLocator不会通知它未找到邮政编码,而是对给定半径内不存在的所有邮政编码进行半径搜索,以决定应为1.

Instead of notifying that it didn't find a zip code, phpZipLocator does a radius search of all zip codes within a given radius of something that doesn't exist, which it decides should be 1.

如果我使用字符串设置邮政编码

If I set the zip code using a string

$zip1 = '02446';

我得到正确的结果.

恕我直言,似乎phpZipLocator可以使用一些工作.

IMHO it seems like phpZipLocator could use a little work.

这篇关于在特定半径中查找邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆