Module: Gmaps4rails::ActsAsGmappable::InstanceMethods
- Defined in:
- lib/gmaps4rails/acts_as_gmappable.rb
Instance Method Summary collapse
-
#process_geocoding ⇒ Object
This is a before_filter to trigger the geocoding and save its results.
- #to_gmaps4rails(&block) ⇒ Object
Instance Method Details
#process_geocoding ⇒ Object
This is a before_filter to trigger the geocoding and save its results
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gmaps4rails/acts_as_gmappable.rb', line 13 def process_geocoding #to prevent geocoding each time a save is made return true if [:check_process] == true && self.send([:checker]) == true #try to geocode begin coordinates = Gmaps4rails.geocode(self.send([:address]), [:language], false, [:protocol]) rescue GeocodeStatus, GeocodeInvalidQuery => e #address was invalid, add error to address. Rails.logger.warn(e) errors[[:address]] << [:msg] if Gmaps4rails.condition_eval(self, [:validation]) rescue GeocodeNetStatus => e #connection error, No need to prevent save. Rails.logger.warn(e) #TODO add customization here? else #if no exception, save the values self.send([:lng_column]+"=", coordinates.first[:lng]) if self.respond_to?([:lng_column]+"=") self.send([:lat_column]+"=", coordinates.first[:lat]) if self.respond_to?([:lat_column]+"=") unless [:normalized_address].nil? self.send([:normalized_address].to_s+"=", coordinates.first[:matched_address]) end # Call the callback method to let the user do what he wants with the data self.send([:callback], coordinates.first[:full_data]) unless [:callback].nil? if Gmaps4rails.condition_eval(self, [:check_process]) self[[:checker]] = true end end end |
#to_gmaps4rails(&block) ⇒ Object
39 40 41 42 43 |
# File 'lib/gmaps4rails/acts_as_gmappable.rb', line 39 def to_gmaps4rails(&block) json = "[" json << Gmaps4rails.create_json(self, &block) #removes the extra comma json << "]" end |