pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='clfc5'></bdo><ul id='clfc5'></ul>

    <i id='clfc5'><tr id='clfc5'><dt id='clfc5'><q id='clfc5'><span id='clfc5'><b id='clfc5'><form id='clfc5'><ins id='clfc5'></ins><ul id='clfc5'></ul><sub id='clfc5'></sub></form><legend id='clfc5'></legend><bdo id='clfc5'><pre id='clfc5'><center id='clfc5'></center></pre></bdo></b><th id='clfc5'></th></span></q></dt></tr></i><div class="z777n75" id='clfc5'><tfoot id='clfc5'></tfoot><dl id='clfc5'><fieldset id='clfc5'></fieldset></dl></div>
    <tfoot id='clfc5'></tfoot>

    <small id='clfc5'></small><noframes id='clfc5'>

  • <legend id='clfc5'><style id='clfc5'><dir id='clfc5'><q id='clfc5'></q></dir></style></legend>

      1. 查找郵政編碼 10 英里范圍內的城鎮.谷歌地圖AP

        Finding towns within a 10 mile radius of postcode. Google maps API(查找郵政編碼 10 英里范圍內的城鎮.谷歌地圖API)

        <small id='LmLvL'></small><noframes id='LmLvL'>

          <bdo id='LmLvL'></bdo><ul id='LmLvL'></ul>
            <tbody id='LmLvL'></tbody>

              • <legend id='LmLvL'><style id='LmLvL'><dir id='LmLvL'><q id='LmLvL'></q></dir></style></legend>

                  <i id='LmLvL'><tr id='LmLvL'><dt id='LmLvL'><q id='LmLvL'><span id='LmLvL'><b id='LmLvL'><form id='LmLvL'><ins id='LmLvL'></ins><ul id='LmLvL'></ul><sub id='LmLvL'></sub></form><legend id='LmLvL'></legend><bdo id='LmLvL'><pre id='LmLvL'><center id='LmLvL'></center></pre></bdo></b><th id='LmLvL'></th></span></q></dt></tr></i><div class="t57nr5p" id='LmLvL'><tfoot id='LmLvL'></tfoot><dl id='LmLvL'><fieldset id='LmLvL'></fieldset></dl></div>
                1. <tfoot id='LmLvL'></tfoot>
                  本文介紹了查找郵政編碼 10 英里范圍內的城鎮.谷歌地圖API的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我最近開始研究 Google Maps API 以在我的網站中嘗試一些新的東西.我目前正在使用此代碼:

                  I've recently started looking at the Google Maps API to try out something new in my websites. I am currently using this code:

                  <?php
                  
                  $postcode = $_REQUEST['postcode'];
                  
                  $url = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$postcode.'&sensor=false';
                  $parsedXML = simplexml_load_file($url);
                  
                  if($parsedXML->status != "OK") {
                  echo "There has been a problem: " . $parsedXML->status;
                  }
                  
                  $myAddress = array();
                  foreach($parsedXML->result->address_component as $component) {
                  if(is_array($component->type)) $type = (string)$component->type[0];
                  else $type = (string)$component->type;
                  
                  $myAddress[$type] = (string)$component->long_name;
                  }
                  header('Content-Type: application/json');
                  echo json_encode($myAddress);
                  
                  
                  ?>
                  

                  它只使用我定義的郵政編碼并搜索 Google 數據庫,然后返回城鎮、縣等.

                  which simply uses a postcode that I define and searches the Google database and then returns the town, county etc.

                  如果可能,我不僅想顯示最近的城鎮,還想顯示 5-10 英里范圍內的任何城鎮.有人能告訴我我會怎么做嗎?

                  If possible, I would like to not only show the nearest town but also any within a 5-10 mile radius. Could someone tell me how I would go about doing this please?

                  感謝您的幫助

                  推薦答案

                  更新:我在 http://www.mullie.eu/geographic-searches/

                  --

                  使用 Google Maps API 遍歷所有可用城鎮以獲取其緯度和經度.將這些保存在某處(數據庫).- 請注意,Google 不會接聽大量電話,因此請限制您的電話.

                  Loop through all available towns using the Google Maps API to fetch their latitude & longitude. Save these somewhere (database). - Beware, Google will not accept an enormous amount of calls, so throttle your calls.

                  然后,在抓取城鎮時,可以使用類似于下面代碼的代碼抓取一定范圍內的城市:

                  Then, when fetching a town, you can use code similar to the code below to grab the cities withing a certain range:

                  public static function getNearby($lat, $lng, $type = 'cities', $limit = 50, $distance = 50, $unit = 'km')
                  {
                      // radius of earth; @note: the earth is not perfectly spherical, but this is considered the 'mean radius'
                      if ($unit == 'km') $radius = 6371.009; // in kilometers
                      elseif ($unit == 'mi') $radius = 3958.761; // in miles
                  
                      // latitude boundaries
                      $maxLat = (float) $lat + rad2deg($distance / $radius);
                      $minLat = (float) $lat - rad2deg($distance / $radius);
                  
                      // longitude boundaries (longitude gets smaller when latitude increases)
                      $maxLng = (float) $lng + rad2deg($distance / $radius / cos(deg2rad((float) $lat)));
                      $minLng = (float) $lng - rad2deg($distance / $radius / cos(deg2rad((float) $lat)));
                  
                      // get results ordered by distance (approx)
                      $nearby = (array) FrontendDB::getDB()->retrieve('SELECT *
                                                                      FROM table
                                                                      WHERE lat > ? AND lat < ? AND lng > ? AND lng < ?
                                                                      ORDER BY ABS(lat - ?) + ABS(lng - ?) ASC
                                                                      LIMIT ?;',
                                                                      array($minLat, $maxLat, $minLng, $maxLng, (float) $lat, (float) $lng, (int) $limit));
                  
                      return $nearby;
                  }
                  

                  上述代碼注意事項:

                  • 使用自己的數據庫包裝器,因此轉換為 mysql_query、PDO、...
                  • 這不會是準確的.我們無法在 DB 中進行精確的球面計算,因此我們采用了上面的 &低緯度經度限制.這基本上意味著一個位置比您的距離稍遠(例如在遠東北,就在實際半徑之外(實際上幾乎是一個圓),但仍在最大緯度和經度內(因為我們將其與數據庫中的平方限制進行比較).這將只是粗略但 100% 準確地選擇您半徑范圍內的城市.

                  我將嘗試說明這一點:

                  _________________
                  |      /       |
                  | Y  /         |
                  |  /           |
                  |(      X      )|
                  |           /  |
                  |         /    |
                  |______\_/______|
                  

                  上面的圓(有點)是你想要在其中找到位置的實際半徑,基于位置 X.這很難直接從你的數據庫中完成,所以我們實際上從數據庫中獲取的是周圍的正方形.如您所見,位置(如 Y)有可能落在這些 max & 范圍內.最小邊界,盡管它們實際上并不在請求的半徑范圍內.不過這些可以稍后通過 PHP 過濾掉.

                  The above circle (somewhat) is the actual radius where you want to find locations within, based upon location X. This is too hard to accomplish straight out of your DB, so what we actually fetch from the DB is the surrounding square. As you can see, it's possible that locations (like Y) fall within these max & min boundaries, though they aren't actually withing the requested radius. These can later be filtered out through PHP though.

                  為了解決最后一個問題,您可以循環所有結果并計算您的根位置和找到的接近匹配之間的確切距離,以計算它們是否實際上在您的半徑內.為此,您可以使用以下代碼:

                  To tackle this last issue, you could loop all results and calculate the exact distance between both your root location, and the close matches found, to calculate if they're actually within your radius. For that, you could use this code:

                  public static function getDistance($lat1, $lng1, $lat2, $lng2, $unit = 'km')
                  {
                      // radius of earth; @note: the earth is not perfectly spherical, but this is considered the 'mean radius'
                      if ($unit == 'km') $radius = 6371.009; // in kilometers
                      elseif ($unit == 'mi') $radius = 3958.761; // in miles
                  
                      // convert degrees to radians
                      $lat1 = deg2rad((float) $lat1);
                      $lng1 = deg2rad((float) $lng1);
                      $lat2 = deg2rad((float) $lat2);
                      $lng2 = deg2rad((float) $lng2);
                  
                      // great circle distance formula
                      return $radius * acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lng1 - $lng2));
                  }
                  

                  這將計算位置 X 和位置 Y 之間的(準)精確距離,然后您可以準確地過濾掉那些足夠近以通過粗略數據庫提取的城市,但又不只是足夠近以實際在您的范圍內邊界.

                  This will calculate the (quasi) exact distance between location X and location Y, and then you can filter out exactly those cities that were near enough to pass the rough db-fetch, but not just near enough to actually be within your bounds.

                  這篇關于查找郵政編碼 10 英里范圍內的城鎮.谷歌地圖API的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                      <i id='sMbaw'><tr id='sMbaw'><dt id='sMbaw'><q id='sMbaw'><span id='sMbaw'><b id='sMbaw'><form id='sMbaw'><ins id='sMbaw'></ins><ul id='sMbaw'></ul><sub id='sMbaw'></sub></form><legend id='sMbaw'></legend><bdo id='sMbaw'><pre id='sMbaw'><center id='sMbaw'></center></pre></bdo></b><th id='sMbaw'></th></span></q></dt></tr></i><div class="z7b7vpz" id='sMbaw'><tfoot id='sMbaw'></tfoot><dl id='sMbaw'><fieldset id='sMbaw'></fieldset></dl></div>
                      <tfoot id='sMbaw'></tfoot>

                          <bdo id='sMbaw'></bdo><ul id='sMbaw'></ul>
                          • <small id='sMbaw'></small><noframes id='sMbaw'>

                            <legend id='sMbaw'><style id='sMbaw'><dir id='sMbaw'><q id='sMbaw'></q></dir></style></legend>

                              <tbody id='sMbaw'></tbody>
                            主站蜘蛛池模板: 【中联邦】增稠剂_增稠粉_水性增稠剂_涂料增稠剂_工业增稠剂生产厂家 | 应急灯_消防应急灯_应急照明灯_应急灯厂家-大成智慧官网 | 荣事达手推洗地机_洗地机厂家_驾驶式扫地机_工业清洁设备 | 上海风淋室_上海风淋室厂家_上海风淋室价格_上海伯淋 | 钢衬玻璃厂家,钢衬玻璃管道 -山东东兴扬防腐设备有限公司 | 脑钠肽-白介素4|白介素8试剂盒-研域(上海)化学试剂有限公司 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 大学食堂装修设计_公司餐厅效果图_工厂食堂改造_迈普装饰 | 集菌仪_智能集菌仪_全封闭集菌仪_无菌检查集菌仪厂家-那艾 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 剪刃_纵剪机刀片_分条机刀片-南京雷德机械有限公司 | 自动化展_机器人展_机床展_工业互联网展_广东佛山工博会 | 广州活动策划公司-15+年专业大型公关活动策划执行管理经验-睿阳广告 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器 | 低气压试验箱_高低温低气压试验箱_低气压实验箱 |林频试验设备品牌 | 连续油炸机,全自动油炸机,花生米油炸机-烟台茂源食品机械制造有限公司 | 全自动翻转振荡器-浸出式水平振荡器厂家-土壤干燥箱价格-常州普天仪器 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 标准光源箱|对色灯箱|色差仪|光泽度仪|涂层测厚仪_HRC大品牌生产厂家 | 上海璟文空运首页_一级航空货运代理公司_机场快递当日达 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 道康宁消泡剂-瓦克-大川进口消泡剂供应商 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 继电器模组-IO端子台-plc连接线-省配线模组厂家-世麦德 | 活性炭-蜂窝-椰壳-柱状-粉状活性炭-河南唐达净水材料有限公司 | 石英陶瓷,石英坩埚,二氧化硅陶瓷-淄博百特高新材料有限公司 | 学生作文网_中小学生作文大全与写作指导 | 宁夏档案密集柜,智能密集柜,电动手摇密集柜-盛隆柜业宁夏档案密集柜厂家 | 电镀电源整流器_高频电解电源_单脉双脉冲电源 - 东阳市旭东电子科技 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 急救箱-应急箱-急救包厂家-北京红立方医疗设备有限公司 | 无锡不干胶标签,卷筒标签,无锡瑞彩包装材料有限公司 | 众品家具网-家具品牌招商_家具代理加盟_家具门户的首选网络媒体。 | 穿线管|波纹穿线管|包塑金属软管|蛇皮管?闵彬专注弱电工程? | 电子厂招聘_工厂招聘_普工招聘_小时工招聘信息平台-众立方招工网 | 粉末包装机-给袋式包装机-全自动包装机-颗粒-液体-食品-酱腌菜包装机生产线【润立机械】 | 干粉砂浆设备_干混砂浆生产线_腻子粉加工设备_石膏抹灰砂浆生产成套设备厂家_干粉混合设备_砂子烘干机--郑州铭将机械设备有限公司 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 低压载波电能表-单相导轨式电能表-华邦电力科技股份有限公司-智能物联网综合管理平台 |