Ruby Geocode: Make a model 'geocoded' when latitude and longitude already exist from other source? -
in app have model , retrieving lat , lng values each row external api unrelated geocode. @ time need geocode .nearbys method lets me find other nearby models within default radius (50 miles) or 1 specify.
normally "active" model geocode adding geocoded_by :attribute_name, attribute_name used geocode when object saved fetch lat/long coordinates.
right i've added model work:
geocoded_by :blargh, latitude: :lat, longitude: :lng def blargh end this seems work fine. can open console, instantiate model, , call model.nearbys. however, seems bit hacky , i'm wondering if there's better way defining fake method , passing geocoded_by. many in advance help!
yesterday had same issue, if old question share here solution in case else needs it.
you can directly include geocoder gem on model requiring file , defining geocoder options (these in case simple names of latitude , longitude on db columns).
since i'm working activerecord model needed to:
require "geocoder/stores/active_record" class user < activerecord::base include geocoder::store::activerecord def self.geocoder_options { latitude: 'latitude', longitude: 'longitude' } end end i think cleaner solution having fake address method.
Comments
Post a Comment