2011-07-04 2 views
3

RailsCasts #273을보고 난 후에 Geocoder 보석을 사용하고 싶습니다. 나는 본 적이 :지오 코더 (Geocoder) 젬 지오 코딩 (Geocoding) 역방향 지오 코딩

class Skatepark < ActiveRecord::Base 
    reverse_geocoded_by :latitude, :longitude 
    after_validation :fetch_address 
    ... 
end 

을 지리 좌표를 반대하고 형식이 지정된으로 :address을 채울 것이다.

이 나는이 지오 코더 보석에서 :street, :locality, :region, :country:postal_code으로 분리받을 수 있습니까?

답변

5

귀하의 모델을 모르지만 귀하의 모델을 작성하는 방법입니다. 또한 귀하가 언급 한 페이지에 문서화되어 있습니다.

class Skatepark < ActiveRecord::Base 
    reverse_geocoded_by :latitude, :longitude do |obj, results| 
    if geo = results.first 
     # populate your model 
     obj.city = geo.city 
     obj.zipcode = geo.postal_code 
     obj.country = geo.country_code 
    end 
    end 
    after_validation :fetch_address 
    ... 
end 
+0

내가 어떻게 보지 못했는지 모릅니다. 도와 주셔서 감사합니다! –