Module: Gmaps4rails::ActsAsGmappable::InstanceMethods

Defined in:
lib/acts_as_gmappable/base.rb

Instance Method Summary collapse

Instance Method Details

#process_geocodingObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/acts_as_gmappable/base.rb', line 138

def process_geocoding
  #to prevent geocoding each time a save is made
  return true if gmaps4rails_options[:check_process] == true && self.send(gmaps4rails_options[:checker]) == true
  begin
    coordinates = Gmaps4rails.geocode(self.send(gmaps4rails_options[:address]))
  rescue GeocodeStatus #address was invalid, add error to base.
    errors[gmaps4rails_options[:address]] << gmaps4rails_options[:msg] if gmaps4rails_options[:validation]
  rescue GeocodeNetStatus => e #connection error, No need to prevent save.
    logger.warn(e)
    #TODO add customization here?
  else #if no exception
    self[gmaps4rails_options[:lng_column]] = coordinates.first[:lng]
    self[gmaps4rails_options[:lat_column]] = coordinates.first[:lat]
    unless gmaps4rails_options[:normalized_address].nil?
      self.send(gmaps4rails_options[:normalized_address].to_s+"=", coordinates.first[:matched_address])
    end
    if gmaps4rails_options[:check_process] == true
      self[gmaps4rails_options[:checker]] = true
    end
  end
end

#to_gmaps4railsObject



160
161
162
163
164
# File 'lib/acts_as_gmappable/base.rb', line 160

def to_gmaps4rails
  json = "["
  json += Gmaps4rails.create_json(self).to_s.chop.chop #removes the extra comma
  json += "]"
end