module Geocoder::Store::MongoBase
Public Class Methods
included_by_model(base)
click to toggle source
# File lib/geocoder/stores/mongo_base.rb, line 4 def self.included_by_model(base) base.class_eval do scope :geocoded, lambda { where(geocoder_options[:coordinates].ne => nil) } scope :not_geocoded, lambda { where(geocoder_options[:coordinates] => nil) } end end
Public Instance Methods
geocode()
click to toggle source
Look up coordinates and assign to latitude
and longitude
attributes (or other as specified in geocoded_by
). Returns coordinates (array).
# File lib/geocoder/stores/mongo_base.rb, line 31 def geocode do_lookup(false) do |o,rs| if r = rs.first unless r.coordinates.nil? o.__send__ "#{self.class.geocoder_options[:coordinates]}=", r.coordinates.reverse end r.coordinates end end end
reverse_geocode()
click to toggle source
Look up address and assign to address
attribute (or other as specified in reverse_geocoded_by
). Returns address (string).
# File lib/geocoder/stores/mongo_base.rb, line 46 def reverse_geocode do_lookup(true) do |o,rs| if r = rs.first unless r.address.nil? o.__send__ "#{self.class.geocoder_options[:fetched_address]}=", r.address end r.address end end end
to_coordinates()
click to toggle source
Coordinates [lat,lon] of the object. This method always returns coordinates in lat,lon order, even though internally they are stored in the opposite order.
# File lib/geocoder/stores/mongo_base.rb, line 22 def to_coordinates coords = send(self.class.geocoder_options[:coordinates]) coords.is_a?(Array) ? coords.reverse : [] end