使用5或10英里的邮政编码进行搜索 [英] Get Search with in 5 or 10 miles of post code

查看:79
本文介绍了使用5或10英里的邮政编码进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张桌子,第1张有邮政编码和类别,第二张有邮政编码,纬度和经度。现在我想搜索...在移动到我的问题之前听到表格格式

 ** Table1(uk_data)** 
** comp_post_code ** cat1 ** cat2 **

**表2(uk_pc)**
**邮政编码**纬度**经度**





现在我想通过成本代码搜索cat1和cat2 ...我已经做了......这里是

  SELECT  * 来自 uk_data 其中​​ 
cat10 like :comp_post_code AND
cat1 like :cat
cat2 喜欢:cat)



这给了我这个邮政编码的结果但现在我想搜索5个矿区和10英里区域的物品我该怎么办?

< ; br>

我知道如何计算p之间的距离ostcodes但这里是代码

函数距离($ lat1,$ lon1,$ lat2,$ lon2,$ unit){

< span class =code-sdkkeyword> $ theta = $ lon1 - $ lon2 ;
$ dist = sin(deg2rad($ lat1))* sin(deg2rad($ lat2))+ cos(deg2rad($ lat1))* cos( deg2rad($ lat2))* cos(deg2rad($ theta));
$ dist = acos($ dist);
$ dist = rad2deg($ dist);
$ miles = $ dist * 60 * 1.1515;
$ unit = strtoupper($ unit);

if ($ unit == K){
return ($ miles * 1.609344);
} else if ($ unit == N){
return ($ miles * 0.8684);
} 其他 {
返回 $英里;
}
}



但是我不知道怎样才能将这个循环变为小鸡表2以获得5或10的结果里程...请帮助

解决方案

lat1,


lon1,


lat2 ,

I have 2 tables 1st with post code and category and second with postcodes, latitude and longitude. Now i want to search ... hear is table format before i move to my question

**Table1 (uk_data)** 
 **comp_post_code**   cat1  **cat2**

**Table2 (uk_pc)** 
 **Postcode**   Latitude  **Longitude**



Now I want to search cat1 and cat2 by cost code ... which i have made ...here it is

SELECT * from uk_data where
cat10 like :comp_post_code  AND (
cat1 like :cat OR
cat2 like :cat)


This gives me result which is on this post code but Now i want to search items where are with in 5 mines and 10 miles of area how can i do that ?
<br>
I know how to calculate distance between postcodes but here is the code

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}


But dont know how can i get this in loop to chick Table 2 for get result in 5 or 10 miles ... please help

解决方案

lat1,


lon1,


lat2,


这篇关于使用5或10英里的邮政编码进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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