我注意到了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