Title: WP GeoNames
Author: Jacques Malgrange
Published: <strong>2014 年 11 月 27 日</strong>
Last modified: 2025 年 5 月 2 日

---

搜尋外掛

![](https://ps.w.org/wp-geonames/assets/banner-772x250.png?rev=1033712)

![](https://ps.w.org/wp-geonames/assets/icon-128x128.png?rev=1033712)

# WP GeoNames

 由 [Jacques Malgrange](https://profiles.wordpress.org/sojahu/) 開發

[下載](https://downloads.wordpress.org/plugin/wp-geonames.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/wp-geonames/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/wp-geonames/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/wp-geonames/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/wp-geonames/#developers)

 [技術支援](https://wordpress.org/support/plugin/wp-geonames/)

## 外掛說明

This lightweight plugin makes it easy to install the millions of GEONAMES Data on
your WordPress site.
 It allows :

 * Install data from one or more file (place & postal code) ;
 * Choose column to install to avoid excessive enlargement of the base ;
 * Choose type of data to install (city, park, road…) ;
 * Remove all the data.
 * Check data in the database.
 * Edit and change datas from Dashboard.
 * Display the places on OpenStreetMap.

A shortcode is also available to create a city region and country taxonomy.

This plugin will give you plenty of ideas to improve the quality of your website.

Official [GeoNames](http://www.geonames.org/) website.

### 1.9.1

05/12/2024

 * Fix XSS vulnerability in shortcode attributes
 * Fix translation issue with WP 6.7

#### 1.9

18/10/2024 – Fix XSS vulnerability on geoSearch field

#### 1.8

08/02/2022

 * Update Leaflet 1.7.1.
 * Update SumoSelect 3.4.2.
 * Split admin sidet in a specific file.

#### 1.7

21/03/2020

 * Fix issue with very long line in Geoname DB.
 * Add nonce.
 * Braces style standardisation in the code.

#### 1.6

14/03/2019 – Add Postal code database.

#### 1.5.1

27/01/2018 – Curl used by default if exists in place of File_Get_Content.

#### 1.5

12/01/2018 – Add tab to edit and change datas.

#### 1.4

24/06/2017

 * Add Taxonomy.
 * Add shortcode to create taxonomy in the site.
 * Add template to customize the taxonomy form.
 * Ability to download multiple files in one click.
 * Check the database with a taxonomy form and display the place on OpenStreetMap.
 * Multisite.

#### 1.3

09/10/2015 – Fix “Fatal error: Out of memory (allocated xxx) (tried to allocate 
xxx bytes)”.

07/06/2016 – 1.3.1 – Fix error when reactivate (header already sent…).

#### 1.2

06/08/2015 – Fix installation bug.

#### 1.1

01/12/2014 – Add Ajax hook.

#### 1.0

25/11/2014 – First stable version.

## 螢幕擷圖

 * [[
 * WP-GeoNames main tab in the Dashboard.
 * [[
 * Check your database in Dashboard.

## 安裝方式

#### Install and Activate

 1. Unzip the downloaded wp-geonames zip file
 2. Upload the `wp-geonames` folder and its contents into the `wp-content/plugins/`
    directory of your WordPress installation
 3. Activate WP GeoNames from Plugins page

#### Insert GeoNames data

 1. Go to the new tab in Settings : WP GeoNames
 2. Select the GeoNames file you want
 3. Select Columns you want to insert (latitude, longitude, population, elevation…)
 4. Select type of data you want (city, building, lake, mountain…)
 5. Click ADD

You can insert as many file as you want.

#### Use

You must use the WordPress tools to get the database. **WPDB is your friend**.
 
You can write the code directly in your template or in functions.php of your theme.

Name of the table : ($wpdb->prefix)geonames

Names of the columns :

 * `idwpgn` (bigint)
 * `geonameid` (bigint)
 * `name` (varchar)
 * `asciiname` (varchar)
 * `alternatenames` (text)
 * `latitude` (decimal)
 * `longitude` (decimal)
 * `feature_class` (char)
 * `feature_code` (varchar)
 * `country_code` (varchar)
 * `cc2` (varchar)
 * `admin1_code` (varchar)
 * `admin2_code` (varchar)
 * `admin3_code` (varchar)
 * `admin4_code` (varchar)
 * `population` (bigint)
 * `elevation` (int)
 * `dem` (smallint)
 * `timezone` (varchar)
 * `modification_date` (date)

Feature Class & Code [here](http://www.geonames.org/export/codes.html).

Example : get GPS position for a specific city in a specific country :

    ```
    global $wpdb;
    $s = $wpdb->get_row("SELECT latitude, longitude 
        FROM ".$wpdb->prefix."geonames 
        WHERE name='Paris' and country_code='FR' ");
    echo $s->latitude . " - " . $s->longitude;
    ```

Example : 10 most populous cities in Switzerland :

    ```
    global $wpdb;
    $s = $wpdb->get_results("SELECT name, population 
        FROM ".$wpdb->prefix."geonames 
        WHERE country_code='CH' and feature_class='P' 
        ORDER BY population DESC 
        LIMIT 10");
    foreach($s as $t) {
        echo $t->name. " : " . $t->population . "<br />";
    }
    ```

Example : hotels within 40 km from Marbella (ES) :

    ```
    global $wpdb;
    $p = $wpdb->get_row("SELECT latitude, longitude 
        FROM ".$wpdb->prefix."geonames 
        WHERE name='Marbella' and country_code='ES' ");
    $dlat = 40 / 1.852 / 60;
    $dlon = 40 / 1.852 / 60 / cos($p->latitude * 0.0174533);
    $s = $wpdb->get_results("SELECT name, latitude, longitude
        FROM ".$wpdb->prefix."geonames 
        WHERE country_code='ES' and 
            feature_code='HTL' and 
            latitude<".($p->latitude+$dlat)." and
            latitude>".($p->latitude-$dlat)." and
            longitude<".($p->longitude+$dlon)." and
            longitude>".($p->longitude-$dlon)."
        LIMIT 100");
    foreach($s as $t) {
        $d = (floor(sqrt(pow(($p->latitude-$t->latitude)*60*1.852,2)+pow(($p->longitude-$t->longitude)*60*1.852*cos($p->latitude * 0.0174533),2))));
        if($d<=40) echo $t->name. " : " . $d . " km<br />";
    }
    ```

Example : Suggest cities during the typing by the user (like Google search)

You must use Ajax action and PHP function with the name **“wpgeonamesAjax”**

In your theme, in function.php ; add :
 function wpgeonamesAjax() { global $wpdb;
$s = $wpdb->get_results(“SELECT name FROM “.$wpdb->prefix.”geonames WHERE country_code
=’FR’ and feature_class=’P’ and name LIKE ‘”.strip_tags($_POST[“city”]).”%’ ORDER
BY name LIMIT 10″); foreach($s as $t) { echo ‘

‘.$t->name.’

‘;
 } }

In your theme, in the right page ; add :

    ```
    <input id="inpCity" name="inpCity" type="text" onkeyup="sugg(this,'<?php echo admin_url('admin-ajax.php'); ?>');" />
    <div class="suggCity" id="suggCity"></div>
    <script>
    function sugg(f,g){
        jQuery(document).ready(function(){
            jQuery.post(g,{'action':'wpgeonamesAjax','city':f.value},function(r){
                jQuery('#suggCity').empty();jQuery('#suggCity').append(r.substring(0,r.length-1));
            });
        });
    }
    </script>
    ```

## 使用者評論

![](https://secure.gravatar.com/avatar/23ef2095e388c95760a8259a975a1039dc64647cfce0c1b87e35181aaa9b21f1?
s=60&d=retro&r=g)

### 󠀁[Great!](https://wordpress.org/support/topic/great-7196/)󠁿

 [thommycgn](https://profiles.wordpress.org/thommycgn/) 2017 年 10 月 23 日

Thank you for this great plugin! It saved me a lot of work!

 [ 閱讀全部 2 則使用者評論 ](https://wordpress.org/support/plugin/wp-geonames/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈WP GeoNames〉的開發相關工作。

參與者

 *   [ Jacques Malgrange ](https://profiles.wordpress.org/sojahu/)

[將〈WP GeoNames〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/wp-geonames)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/wp-geonames/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/wp-geonames/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/wp-geonames/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/wp-geonames/)。

## 變更記錄

#### 1.9.2

02/05/2025 – Fix translation warning with WP 6.8

## 中繼資料

 *  版本 **1.9.2**
 *  最後更新 **1 年前**
 *  啟用安裝數 **200+**
 *  WordPress 版本需求 ** 3.0.1 或更新版本 **
 *  已測試相容的 WordPress 版本 **6.7.5**
 *  PHP 版本需求 ** 5.3 或更新版本 **
 *  語言
 * [English (US)](https://wordpress.org/plugins/wp-geonames/)
 * 標籤:
 * [city](https://tw.wordpress.org/plugins/tags/city/)[data](https://tw.wordpress.org/plugins/tags/data/)
   [geo](https://tw.wordpress.org/plugins/tags/geo/)[sql](https://tw.wordpress.org/plugins/tags/sql/)
   [table](https://tw.wordpress.org/plugins/tags/table/)
 *  [進階檢視](https://tw.wordpress.org/plugins/wp-geonames/advanced/)

## 評分

 5 星，滿分為 5 星

 *  [  2 個 5 星使用者評論     ](https://wordpress.org/support/plugin/wp-geonames/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/wp-geonames/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/wp-geonames/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/wp-geonames/reviews/?filter=2)
 *  [  0 個 1 星使用者評論     ](https://wordpress.org/support/plugin/wp-geonames/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/wp-geonames/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/wp-geonames/reviews/)

## 參與者

 *   [ Jacques Malgrange ](https://profiles.wordpress.org/sojahu/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/wp-geonames/)

## 贊助

想要支援這個外掛的發展嗎？

 [ 贊助這個外掛 ](https://www.paypal.me/JacquesMalgrange)