我在这里找到了很多计算和一些 php 示例,大多数都只是在我的脑海中。
我找到了这个例子:
SELECT b.zip_code, b.state,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((a.lat-b.lat)*0.017453293)/2),2) +
COS(a.lat*0.017453293) *
COS(b.lat*0.017453293) *
POWER(SIN(((a.lng-b.lng)*0.017453293)/2),2))))) AS distance
FROM zips a, zips b
WHERE
a.zip_code = '90210' ## I would use the users submitted value
GROUP BY distance
having distance <= 5; ## I would use the users submitted value
但是,我无法理解如何使用我的数据库实现查询。
看起来该查询具有我所需要的一切。
但是,我什至无法找到/理解 b.zip_code 实际上是什么!(b.
和是zips a, zips b
什么?)
我也不需要state
查询中的。
我的 mySQL 数据库结构是这样的:
ZIP | LAT | LONG
33416 | 26.6654 | -80.0929
我写这个是为了返回某种结果(不是基于上面的查询),但是它只踢出一个邮政编码。
## Just for a test BUT, in reality I desire to SELECT a zip code WHERE ZIP = the users submitted zip code
## not by a submitted lat lon. I left off the $connect var, assume it's there.
my $set1 = (26.6654 - 0.20);
my $set2 = (26.6654 + 0.20);
my $set3 = (-80.0929 - 0.143);
my $set4 = (-80.0929 + 0.143);
my $test123 = $connect->prepare(qq{SELECT `ZIP` FROM `POSTAL`
WHERE `LAT` >= ? AND `LAT` <= ?
AND `LONG` >= ? AND `LONG` <= ?}) or die "$DBI::errstr";
$test123->execute("$set1","$set2","$set3","$set4") or die "$DBI::errstr";
my $cntr;
while(@zip = $test123->fetchrow_array()) {
print qq~$zip[$cntr]~;
push(@zips,$zip[$cntr]);
$cntr++;
}
正如你所看到的,我是个新手,所以我需要一些手和详细的解释。
因此,在 Perl 中,如何将邮政编码从用户提交的邮政编码推送到数组中,并且用户提交的距离以英里为单位。可以是正方形而不是圆形,并不是对某个功能的批评。越快越好。