我已經在獅身人面像兩個數據源最近的城市:使用PHP獅身人面像API我已經做搜索25英里範圍內匹配的列表按名稱城市和搜索發現有上市(企業)
source cities {
...
sql_query = SELECT id, city_name, state_name, state_abbr, latitude,
longitude, population FROM cities;
sql_attr_uint = population
sql_attr_float = latitude
sql_attr_float = longitude
...
}
source listings {
...
sql_query = SELECT entry_id, title, url_title, category_names,
address1, address2, city, state, zip, latitude, longitude,
listing_summary, listing_url, extended_info FROM listings;
sql_attr_float = latitude
sql_attr_float = longitude
...
}
一個緯度/長度沒有任何問題,但現在我需要加入他們......我想能夠:
a)當通過名稱搜索城市時,只返回內有列表的城市25英里和 b)當我查看一個城市(緯度/長度已知)的結果時,拉出距離它們不到25英里的最近3個城市
有沒有辦法構建一個單一的獅身人面像搜索來完成這兩個查找?
編輯基於下面的評論鏈:
我已經更新了我的城市表,包括類型點的場點,並建立在其上的空間索引:
> describe cities_copy; +-------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-----------------------+------+-----+---------+----------------+ | id | mediumint(7) unsigned | NO | PRI | NULL | auto_increment | | city_name | varchar(64) | NO | MUL | NULL | | | state_name | varchar(64) | NO | | NULL | | | state_abbr | varchar(8) | NO | | NULL | | | county_name | varchar(64) | NO | | NULL | | | county_id | smallint(3) unsigned | NO | | NULL | | | latitude | float(13,10) | NO | MUL | NULL | | | longitude | float(13,10) | NO | | NULL | | | population | int(8) unsigned | NO | MUL | NULL | | | point | point | NO | MUL | NULL | | +-------------+-----------------------+------+-----+---------+----------------+ > show indexes from cities_copy; +-------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | cities_copy | 0 | PRIMARY | 1 | id | A | 23990 | NULL | NULL | | BTREE | | | cities_copy | 0 | city/state | 1 | city_name | A | NULL | NULL | NULL | | BTREE | | | cities_copy | 0 | city/state | 2 | state_abbr | A | 23990 | NULL | NULL | | BTREE | | | cities_copy | 1 | lat/long | 1 | latitude | A | NULL | NULL | NULL | | BTREE | | | cities_copy | 1 | lat/long | 2 | longitude | A | NULL | NULL | NULL | | BTREE | | | cities_copy | 1 | population | 1 | population | A | NULL | NULL | NULL | | BTREE | | | cities_copy | 1 | point | 1 | point | A | NULL | 32 | NULL | | SPATIAL | | +-------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
但是,當我嘗試更新數據以創建分列拉/長數據的我得到一個錯誤:
> update cities_copy set point = Point(latitude, longitude); Cannot get geometry object from data you send to the GEOMETRY field
是我的語法在這裏下車還是我跑陷入其他問題?
如果你的對象是足夠接近對方爲你能夠使用平面地球模型,您需要將您的緯度和經度轉換爲笛卡爾系統,比如說「UTM」或「普爾科沃」或任何最適合你的國家的投影。至於'UPDATE',這個必須是'MySQL'版本的問題。試試這個:'SET coord = GeomFromText(CONCAT('Point(',latitude,'',longitude,')'))','latitude'和'longitude'轉換成笛卡兒系統。 – Quassnoi 2009-10-13 20:20:41
我沒有將lat/long轉換爲笛卡兒,但這正是我上次用來生成點的查詢,最終結果是我不得不使用LineStringFromWKB/AsBinary的東西。 – 2009-10-13 20:24:07
和城市(點)都包含在美國境內(至少現在)。 – 2009-10-13 20:24:47