我写了一个blog解释它是如何工作的。您需要进行地理编码并从geocoder
gem获取相关信息。
用户将使用Geocomplete输入地址并将该地址存储在用户/位置表中的地址列中 然后,使用Geocoder获取其他地理信息并使用地址更新其他列。
这里去................
================用户/地点表,在这里我将使用允许用户使用Geocomplete填写地址,然后用它利用地理编码
class CreateLocations < ActiveRecord::Migration
def change
create_table :places do |t|
t.string :address
t.float :latitude
t.float :longitude
##======here the address field is important==========
t.string :address
t.string :country
t.string :state
t.string :city
t.string :pincode
t.timestamps
end
add_index :places, :address
end
end
得到其他细节================= =在用户/位置模型中使用地址自动填充的地理编码
##i want to use the address column to autopopulate others columns
geocoded_by :address
##also i want to use the latitude.longitude to fetch all others informations and then save in relevant ##feilds
reverse_geocoded_by :latitude, :longitude do |obj,results|
if geo = results.first
obj.state = geo.state
obj.city = geo.city
obj.pincode = geo.postal_code
obj.country = geo.country
end
end
##变/更新/验证地址只有地址变更为其他性能改进每次##时间会不断更新
after_validation :geocode, :reverse_geocode ,:if => :address_changed?
感谢,这正是我需要的 – Adt 2015-03-31 13:10:39