Sha256: 87c3a17ffbae76ebf110dd918a8b70d9614630cbe2b2eef7ba15fe781cee10fb

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

module OnTheMap
  module Mappable  
    extend ActiveSupport::Concern

    included do
      include ::Gmaps4rails::ActsAsGmappable

      include_concerns :geo_locatable, :positionable, from: 'OnTheMap'

      # see https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Model-Customization
      # https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Mongo%C3%AFd
      acts_as_gmappable position: :position,
                        process_geocoding: :gmaps_geocode?, # 
                        address:"gmaps4rails_address", normalized_address: "normalized_address",
                        msg: "Sorry, not even Google could figure out where that is"

      field :gmaps, type: Boolean

      field :normalized_address # used to save address matched by Google
    end

    # When Geo Coding is to be performed by Gmaps4rails
    # Leave it up to geocoder!
    def gmaps_geocode?
      # has_address? && (has_position? || has_geo_coords?) && 
      false # (!address.blank? && (lat.blank? || lng.blank?)) || position_changed?      
    end

    def has_geo_coords?
      respond_to?(:latitude) && latitude && respond_to?(:longitude) && longitude
    end

    def has_position?
      respond_to?(:position) && position
    end

    def has_address?
      respond_to?(:address) && address
    end

    #describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki 
    def gmaps4rails_address
      return address_str if respond_to? :address_str # Use GeoLocatable if such exists
      "#{address.street}, #{address.city}, #{address.country}" 
    end  
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
on_the_map-0.1.5 lib/on_the_map/mappable.rb
on_the_map-0.1.4 lib/on_the_map/mappable.rb
on_the_map-0.1.3 lib/on_the_map/mappable.rb
on_the_map-0.1.1 lib/on_the_map/mappable.rb
on_the_map-0.1.0 lib/on_the_map/mappable.rb