0

私は不動産のWebカタログを開発しており、geokitgemを使用してすべての広告をジオコーディングしたいと考えています。私の質問は、国、選択した国の都市、行政区域、または選択した都市の最寄りの地下鉄駅で検索したい場合、パフォーマンスポイントから最適なデータベースレイアウトは何でしょうか。利用可能な国、都市、行政区域、および大都市圏は、カタログの管理者が定義する必要があり、ジオコーディングによって検証する必要があります。

私は単一のテーブルを思いついた:

  create_table "geo_locations", :force => true do |t|
    t.integer "geo_location_id"                     #parent geo location (ex. country is parent geo location of city  
    t.string  "country",             :null => false #necessary for any geo location
    t.string  "city",                               #not null for city geo location and it's children
    t.string  "administrative_area"                 #not null for administrative_area geo location and it's children
    t.string  "thoroughfare_name"                   #not null for metro station or street name geo location and it's children
    t.string  "premise_number"                      #house number
    t.float   "lng",                 :null => false 
    t.float   "lat",                 :null => false
    t.float   "bound_sw_lat",        :null => false
    t.float   "bound_sw_lng",        :null => false
    t.float   "bound_ne_lat",        :null => false
    t.float   "bound_ne_lng",        :null => false
    t.integer "mappable_id"
    t.string  "mappable_type"
    t.string  "type"                                #country, city, administrative area, metro station or address 
  end

最終的な地理的位置は住所であり、不動産広告のマーカーを地図上に配置するために必要なすべての情報が含まれています。しかし、私はまだ検索機能に固執しています。

どんな助けでも大歓迎です。

4

1 に答える 1

1

Thinking Sphinx を見たいと思うかもしれません。これには、組み込みのジオ検索がサポートされています。これが私が行う方法です。

class Company < ActiveRecord::Base
    define_index do
        indexes :name, :sortable => true
        has 'RADIANS(lat)',  :as => :latitude,  :type => :float
        has 'RADIANS(lng)', :as => :longitude, :type => :float
    end
end
# Searching for companies, sort by closest first
Company.search "bananas", :geo => [lat, lng], :order => "@geodist ASC, @relevance DESC"
于 2010-06-14T21:50:38.937 に答える