久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>
                            主站蜘蛛池模板: 成人av高清 | 国产精品九九九 | 操操网站 | 一区二区三区四区在线免费观看 | 丝袜美腿av | 91免费在线| 97超碰人人 | 日本免费视频在线观看 | 国产成人福利 | 亚洲国产一区二区视频 | 欧美日在线 | 亚洲一区中文字幕 | 精品亚洲一区二区三区四区五区高 | 成人在线视频一区 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 91天堂网 | 免费成人av| 精品欧美乱码久久久久久 | 暴草美女 | 中文字幕免费 | 国产九九精品视频 | 三级免费毛片 | 亚洲v日韩v综合v精品v | 成人在线精品 | 天天草av | 亚洲精品免费视频 | 日韩高清国产一区在线 | 免费v片 | 亚洲综合视频 | 色吊丝2288sds中文字幕 | 天久久| 玖玖色在线视频 | 久久久久久久网 | 久久国产欧美日韩精品 | 偷拍亚洲色图 | 国产精品成人一区 | 亚洲视频免费在线 | 99这里只有精品视频 | 久久成人av | 国产日韩欧美 | 在线午夜电影 |