使用 geokit 具有地理编码功能的应用程序的数据库布局

发布于 2024-09-06 03:26:03 字数 1458 浏览 1 评论 0原文

我正在开发一个房地产网络目录,并希望使用 geokit gem 对每个广告进行地理编码。 我的问题是,如果我想按国家、所选国家的城市、行政区域或所选城市最近的地铁站进行搜索,从性能角度来看,最好的数据库布局是什么。可用的国家、城市、行政区域和地铁站应由目录管理员定义,并且必须通过地理编码进行验证。

我想出了一个表:

  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

最终地理位置是地址,它包含将房地产广告标记放在地图上的所有必要信息。但我仍然停留在搜索功能上。

任何帮助将不胜感激。

I'm developing a real estate web catalogue and want to geocode every ad using geokit gem.
My question is what would be the best database layout from the performance point if i want to make search by country, city of the selected country, administrative area or nearest metro station of the selected city. Available countries, cities, administrative areas and metro sations should be defined by the administrator of catalogue and must be validated by geocoding.

I came up with single table:

  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

Final geo location is address it contains all neccessary information to put marker of the real estate ad on the map. But i'm still stuck on search functionality.

Any help would be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2024-09-13 03:26:03

您可能想看看 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"

You might want to have a look at Thinking Sphinx, it has support for geo-searching built in. This is how I do it:

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文