Google-Maps-for-Rails gem, Force Geocoding of Model
How do I force Google-Maps-for-Rails gem to geocode a model? I开发者_Python百科 dont' want to re-geocode every member, just some.
Along those lines, once a model member has been geocoded and the lon/lat stored in the db, how do I clear that so it re-geocodes?
Could be the same answer for both questions, I don't know.
Your question raised a problem in the gem: it geocoded after each save, not checking the boolean reference. It's fixed now in 0.4.1
By default
- Geocoding is made as part of the save process.
- if the boolean
gmaps == true
, then geocoding is skipped - else the geocoding is done
You can configure it the way you want.
BTW, you could even use the geocoding function:
Gmaps4rails.geocode('your address')
And saves directly the values you want.
See doc here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Methods
you might also want to try the geocoder gem
Adding this to an existing database, I wanted to geocode on access, and then cache the result. So I added an accessor function for latitude and longitude that checks for a value, and if the database doesn't have it, Geocode and save, and then return the value. This way, it gets geocoded "on demand".
精彩评论