开发者

Getting Gmaps4Rails working with MongoMapper

First off, this gem looks awesome -- thanks @apneadiving. I hope to be able to contribute one day -- once I figure out how to use it properly :-\

A horribly newbie question, I fear... and I know I should be able to figure it out based solely on Ruby-isms... But I have failed to figure out what I am doing wrong...

I cannot get past this error:

NoMethodError (undefined method `gmaps4rails_options' for <WaterSupply>...

I have explored many different ways to encode the coords, but the error -- I believe -- is simply in the acts_as_gmappable somehow not "working." My model is this:

class WaterSupply
  include Gmaps4rails::ActsAsGmappable
  include MongoMapper::Document

  acts_as_gmappable :process_geocoding => false

  ensure_index [[:loc, '2d']]

  def initialize
    puts Gmaps4rails::ActsAsGmappable.inspect
    puts "*"*50
  end

  key :name, String, :required => true

  # TODO break this address/geo stuff out into a separate Location class
  key :loc,开发者_开发知识库 GeoPoint, :default => [40.34962381,-74.75102367]
  key :gmaps, Boolean
  key :address, String
  key :city, String
  key :zip, String
  key :country, String

  def gmaps4rails_address
      "#{self.address}, #{self.zip} #{self.city}, #{self.country}"
  end
end

Any help would be appreciated. I can get a blank map to appear, just nothing with any model instance data :-p

Once I get things working, I'll add a blog post or a wiki page for using MongoMapper and Gmaps4Rails!


I got an example working with MongoMapper here

Model class looks like this:

class WaterSupply
  include MongoMapper::Document
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable :lat => 'latitude', :lon => 'longitude', :process_geocoding => true,
                    :check_process => :prevent_geocoding,
                    :address => "address", :normalized_address => "address"
                    #:msg => "Sorry, not even Google could figure out where that is"

  key :name, String
  key :address, String
  key :street, String
  key :zip, String
  key :city, String
  key :state, String
  key :country, String
  key :latitude, Float
  key :longitude, Float
  key :gps, GeoPoint  # lat, lon; e.g., [40.34962381,-74.75102367]
  key :gmaps, Boolean

  ensure_index [[:gps, "2d"]]

  before_save :store_geo

  def store_geo
    self.gps = [self.latitude, self.longitude]
  end

  def prevent_geocoding
    address.blank? || (!latitude.blank? && !longitude.blank?)
  end
  def gmaps4rails_address
    "#{self.street}, #{self.city}, #{self.state} #{self.zip} #{self.country}"
  end
  #def gmaps4rails_infowindow
  #  "#{self.name} #{self.gps}"
  #end
  def gmaps4rails_title
    "#{self.name}"
  end

  def gmaps4rails_sidebar
    "#{self.name} #{self.gps}"
  end

end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜