我注意到了Google Maps for Rails gems,当我更改模型字段中的地址时,坐标不会自动更新,地址栏被更新并保存。我创建了一个调用geocode的before_save方法。使用Google-Maps-For-Rails更新模型地址的坐标
before_save :update_location_coordinates # in model being mapped
protected
def update_location_coordinates
place = Gmaps4rails.geocode(gmaps4rails_address).first
self.longitude, self.latitude = place[:lng], place[:lat] unless place.empty?
rescue
nil
end
这个工程,但我想知道是否有必要,因为它似乎应该是自动的宝石。我错过了什么吗?
感谢...
PS地理编码,所以我只是把第一个(最好的)猜测
太棒了!谢谢。现在,我知道该gmaps字段的用途。我想我错过了它的文档。 – 2011-04-28 13:14:30